diff --git a/crates/wit-component/src/validation.rs b/crates/wit-component/src/validation.rs index 6439d4a4c0..c70e0c8e3b 100644 --- a/crates/wit-component/src/validation.rs +++ b/crates/wit-component/src/validation.rs @@ -174,7 +174,13 @@ pub fn validate_module<'a>( Entry::Vacant(e) => e.insert(IndexMap::new()), }; - assert!(map.insert(import.name, ty).is_none()); + if map.insert(import.name, ty).is_some() { + bail!( + "module has duplicate import for `{}::{}`", + import.module, + import.name + ); + } } _ => bail!("module is only allowed to import functions"), } diff --git a/tests/cli/bad-component-new.wat b/tests/cli/bad-component-new.wat new file mode 100644 index 0000000000..22bf28a522 --- /dev/null +++ b/tests/cli/bad-component-new.wat @@ -0,0 +1,6 @@ +;; FAIL: component new % + +(module + (import "a" "a" (func)) + (import "a" "a" (func)) +) diff --git a/tests/cli/bad-component-new.wat.stderr b/tests/cli/bad-component-new.wat.stderr new file mode 100644 index 0000000000..0bcb399ba0 --- /dev/null +++ b/tests/cli/bad-component-new.wat.stderr @@ -0,0 +1,6 @@ +error: failed to encode a component from module + +Caused by: + 0: failed to decode world from module + 1: module was not valid + 2: module has duplicate import for `a::a`