Skip to content

Commit 790bc04

Browse files
authored
Fix call_ref on empty stack (#2472)
Same issue as #2471 but for `call_ref`. We don't believe there's a prior issue for this.
1 parent 3852498 commit 790bc04

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

src/type-checker.cc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -522,21 +522,14 @@ Result TypeChecker::OnCallIndirect(const TypeVector& param_types,
522522

523523
Result TypeChecker::OnIndexedFuncRef(Index* out_index) {
524524
Type type;
525-
CHECK_RESULT(PeekType(0, &type));
526-
Result result = Result::Ok;
527-
if (!(type == Type::Any || type.IsReferenceWithIndex())) {
528-
TypeVector actual;
529-
actual.push_back(type);
530-
std::string message =
531-
"type mismatch in call_ref, expected reference but got " +
532-
TypesToString(actual);
533-
PrintError("%s", message.c_str());
534-
result = Result::Error;
525+
Result result = PeekType(0, &type);
526+
if (!type.IsReferenceWithIndex()) {
527+
type = Type::Reference;
535528
}
529+
result |= PopAndCheck1Type(type, "call_ref");
536530
if (Succeeded(result)) {
537531
*out_index = type.GetReferenceIndex();
538532
}
539-
result |= DropTypes(1);
540533
return result;
541534
}
542535

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
;;; TOOL: wat2wasm
2+
;;; ARGS: --enable-function-references
3+
;;; ERROR: 1
4+
(module
5+
(func (export "main")
6+
(call_ref
7+
)
8+
)
9+
)
10+
(;; STDERR ;;;
11+
out/test/typecheck/bad-callref-empty.txt:6:6: error: type mismatch in call_ref, expected [reference] but got []
12+
(call_ref
13+
^^^^^^^^
14+
;;; STDERR ;;)

test/typecheck/bad-callref-int32.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
)
1010
)
1111
(;; STDERR ;;;
12-
out/test/typecheck/bad-callref-int32.txt:6:6: error: type mismatch in call_ref, expected reference but got [i32]
12+
out/test/typecheck/bad-callref-int32.txt:6:6: error: type mismatch in call_ref, expected [reference] but got [... i32]
1313
(call_ref (i32.const 10)
1414
^^^^^^^^
1515
;;; STDERR ;;)

test/typecheck/bad-callref-null.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
)
1010
)
1111
(;; STDERR ;;;
12-
out/test/typecheck/bad-callref-null.txt:6:6: error: type mismatch in call_ref, expected reference but got [funcref]
12+
out/test/typecheck/bad-callref-null.txt:6:6: error: type mismatch in call_ref, expected [reference] but got [... funcref]
1313
(call_ref (i32.const 10)
1414
^^^^^^^^
1515
;;; STDERR ;;)

0 commit comments

Comments
 (0)