diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 1eb24b7ff1f..57c2d107eef 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -423,7 +423,7 @@ def get_tests(test_dir, extensions=[], recursive=False): 'if.wast', # Requires more precise unreachable validation 'imports.wast', # Requires fixing handling of mutation to imported globals 'proposals/threads/imports.wast', # Missing memory type validation on instantiation - 'linking.wast', # Missing function type validation on instantiation + 'linking.wast', # Missing global type validation on instantiation 'proposals/threads/memory.wast', # Missing memory type validation on instantiation 'annotations.wast', # String annotations IDs should be allowed 'instance.wast', # Requires support for table default elements @@ -445,8 +445,6 @@ def get_tests(test_dir, extensions=[], recursive=False): 'ref_cast.wast', # Requires host references to not be externalized i31refs 'ref_test.wast', # Requires host references to not be externalized i31refs 'struct.wast', # Fails to roundtrip unnamed types e.g. `(ref 0)` - 'type-rec.wast', # Missing function type validation on instantiation - 'type-subtyping.wast', # ShellExternalInterface::callTable does not handle subtyping 'memory64.wast', # Requires validations on the max memory size 'imports3.wast', # Requires better checking of exports from the special "spectest" module 'relaxed_dot_product.wast', # i16x8.relaxed_dot_i8x16_i7x16_s instruction not supported diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 369745d0b67..40a9d9e54cb 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -3450,9 +3450,7 @@ class ModuleRunnerBase : public ExpressionRunner { if (!MemoryUtils::isSubType(exportedMemory, **memory)) { trap("Imported memory isn't compatible."); } - } - - if (auto** tableDecl = std::get_if(&import)) { + } else if (auto** tableDecl = std::get_if(&import)) { auto* importedTable = importResolver->getTableOrNull( importable->importNames(), **tableDecl); if (!importedTable) { @@ -3468,7 +3466,21 @@ class ModuleRunnerBase : public ExpressionRunner { << " isn't compatible with import declaration: " << **tableDecl) .str()); } + } else if (auto** function = std::get_if(&import)) { + auto exportedFunc = getFunction((*function)->name); + if (!Type::isSubType(exportedFunc.type, (*function)->type)) { + trap((std::stringstream() + << "Imported function " << importable->importNames() + << " with type " + << exportedFunc.type.getHeapType().getSignature().toString() + << " isn't compatible with import declaration with type " + "(modulo rec groups): " + << (*function)->type.getHeapType().getSignature().toString()) + .str()); + } } + + // TODO: remaining cases e.g. globals and tags. }); }