Skip to content

Commit 5db4011

Browse files
Merge pull request #192 from sumleo/fix/path-resolution-unwrap
Fix panic on missing first segment in package path resolution
2 parents 346d475 + c4124ad commit 5db4011

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

crates/wac-parser/src/resolution.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,8 @@ impl<'a> AstResolver<'a> {
25532553
}
25542554

25552555
// Otherwise, project into the parent based on the current segment
2556-
let export = match found.unwrap() {
2556+
let Some(parent) = found else { break };
2557+
let export = match parent {
25572558
// The parent is an interface or instance
25582559
ItemKind::Type(Type::Interface(id)) | ItemKind::Instance(id) => {
25592560
state.graph.types()[id].exports.get(segment).copied()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package test:comp;
2+
3+
interface i {
4+
use foo:bar/nonexistent.{a};
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
failed to resolve document
2+
3+
× package `foo:bar` has no export named `nonexistent`
4+
╭─[tests/resolution/fail/missing-package-definition.wac:4:17]
5+
3 │ interface i {
6+
4 │ use foo:bar/nonexistent.{a};
7+
· ─────┬─────
8+
· ╰── unknown export `nonexistent`
9+
5 │ }
10+
╰────
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(component
2+
(import "foo" (func))
3+
)

0 commit comments

Comments
 (0)