Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Fix a debug-only assert linking assert (#15033)

Alex Crichtonab9558d450d9
diff --git a/crates/wasmtime/src/runtime/component/instance.rs b/crates/wasmtime/src/runtime/component/instance.rs
index 439583f0ea..4713762b08 100644
--- a/crates/wasmtime/src/runtime/component/instance.rs
+++ b/crates/wasmtime/src/runtime/component/instance.rs
@@ -1038,9 +1038,8 @@ impl<'a> Instantiator<'a> {
EngineOrModuleTypeIndex::RecGroup(_) => unreachable!(),
};
let actual = unsafe { f.vm_func_ref(store).as_ref().type_index };
- assert_eq!(
- expected,
- Some(actual),
+ assert!(
+ expected.is_some_and(|e| store.engine().signatures().is_subtype(actual, e)),
"type mismatch for import {imp_module:?} {imp_name:?}!!!\n\n\
expected {:#?}\n\n\
found {:#?}",
diff --git a/tests/misc_testsuite/component-model/core-import-func-subtype.wast b/tests/misc_testsuite/component-model/core-import-func-subtype.wast
new file mode 100644
index 0000000000..ca7d44e07d
--- /dev/null
+++ b/tests/misc_testsuite/component-model/core-import-func-subtype.wast
@@ -0,0 +1,19 @@
+;;! gc = true
+
+;; A core instance inside a component may satisfy a function import of type
+;; `$super` with a function whose type is a declared subtype of `$super`.
+(component
+ (core module $a
+ (type $super (sub (func (result i32))))
+ (type $sub (sub $super (func (result i32))))
+ (func (export "f") (type $sub) i32.const 42))
+ (core module $b
+ (type $super (sub (func (result i32))))
+ (type $g (func (result i32)))
+ (import "a" "f" (func $f (type $super)))
+ (func (export "g") (type $g) call $f))
+ (core instance $a (instantiate $a))
+ (core instance $b (instantiate $b (with "a" (instance $a))))
+ (func (export "g") (result s32) (canon lift (core func $b "g"))))
+
+(assert_return (invoke "g") (s32.const 42))