Skip to content

Commit c4124ad

Browse files
committed
Fix panic on missing first segment in package path resolution
When resolving a multi-segment package path like `foo:bar/nonexistent.{a}`, if the first segment is not found in the package definitions, the code would unwrap None and panic. Now breaks out of the lookup loop when the first segment is not found, falling through to the existing error reporting that produces a clear error message. Added a resolution test case for this scenario.
1 parent e1e684a commit c4124ad

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)