Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/wit-parser/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,17 @@ impl WitPackageDecoder<'_> {
assert!(prev.is_none());
}

// A duplicate mapping here comes from a valid component that WIT cannot
// represent (for example an imported resource re-exported under a new
// name), not an internal invariant, so report it instead of asserting.
let prev = self.type_map.insert(created, ty);
assert!(prev.is_none());
if prev.is_some() {
bail!(
"cannot represent this component in WIT: the type `{name}` appears \
more than once (for example, when an imported instance is \
re-exported under a new name)"
);
}
Ok(ty)
}

Expand Down
6 changes: 6 additions & 0 deletions tests/cli/component-wit-imported-resource-no-reexport.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; RUN: component wit %

(component
(type (;0;) (instance (export "request" (type (sub resource)))))
(import "impl:test/handler" (instance (;0;) (type 0)))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package root:component;

world root {
import impl:test/handler;
}
package impl:test {
interface handler {
resource request;
}
}
7 changes: 7 additions & 0 deletions tests/cli/component-wit-reexport-imported-resource.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; FAIL: component wit %

(component
(type (;0;) (instance (export "request" (type (sub resource)))))
(import "impl:test/handler" (instance (;0;) (type 0)))
(export "wasi:http/handler@0.3.0" (instance 0))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: failed to decode WIT from export `wasi:http/handler@0.3.0`

Caused by:
0: cannot represent this component in WIT: the type `request` appears more than once (for example, when an imported instance is re-exported under a new name)
Loading