diff --git a/src/type-checker.cc b/src/type-checker.cc index 37412e15e5..8d6c3a11f2 100644 --- a/src/type-checker.cc +++ b/src/type-checker.cc @@ -522,21 +522,14 @@ Result TypeChecker::OnCallIndirect(const TypeVector& param_types, Result TypeChecker::OnIndexedFuncRef(Index* out_index) { Type type; - CHECK_RESULT(PeekType(0, &type)); - Result result = Result::Ok; - if (!(type == Type::Any || type.IsReferenceWithIndex())) { - TypeVector actual; - actual.push_back(type); - std::string message = - "type mismatch in call_ref, expected reference but got " + - TypesToString(actual); - PrintError("%s", message.c_str()); - result = Result::Error; + Result result = PeekType(0, &type); + if (!type.IsReferenceWithIndex()) { + type = Type::Reference; } + result |= PopAndCheck1Type(type, "call_ref"); if (Succeeded(result)) { *out_index = type.GetReferenceIndex(); } - result |= DropTypes(1); return result; } diff --git a/test/typecheck/bad-callref-empty.txt b/test/typecheck/bad-callref-empty.txt new file mode 100644 index 0000000000..cee3885352 --- /dev/null +++ b/test/typecheck/bad-callref-empty.txt @@ -0,0 +1,14 @@ +;;; TOOL: wat2wasm +;;; ARGS: --enable-function-references +;;; ERROR: 1 +(module + (func (export "main") + (call_ref + ) + ) +) +(;; STDERR ;;; +out/test/typecheck/bad-callref-empty.txt:6:6: error: type mismatch in call_ref, expected [reference] but got [] + (call_ref + ^^^^^^^^ +;;; STDERR ;;) diff --git a/test/typecheck/bad-callref-int32.txt b/test/typecheck/bad-callref-int32.txt index 52f34da1d8..95401b9504 100644 --- a/test/typecheck/bad-callref-int32.txt +++ b/test/typecheck/bad-callref-int32.txt @@ -9,7 +9,7 @@ ) ) (;; STDERR ;;; -out/test/typecheck/bad-callref-int32.txt:6:6: error: type mismatch in call_ref, expected reference but got [i32] +out/test/typecheck/bad-callref-int32.txt:6:6: error: type mismatch in call_ref, expected [reference] but got [... i32] (call_ref (i32.const 10) ^^^^^^^^ ;;; STDERR ;;) diff --git a/test/typecheck/bad-callref-null.txt b/test/typecheck/bad-callref-null.txt index 0886077738..6771a89367 100644 --- a/test/typecheck/bad-callref-null.txt +++ b/test/typecheck/bad-callref-null.txt @@ -9,7 +9,7 @@ ) ) (;; STDERR ;;; -out/test/typecheck/bad-callref-null.txt:6:6: error: type mismatch in call_ref, expected reference but got [funcref] +out/test/typecheck/bad-callref-null.txt:6:6: error: type mismatch in call_ref, expected [reference] but got [... funcref] (call_ref (i32.const 10) ^^^^^^^^ ;;; STDERR ;;)