Skip to content

Commit 3fd8c70

Browse files
authored
Fix error message for ref.is_null (#2471)
Fixes #2453 in a bit of a silly way. (Conveniently, we already have tests for this, but nobody noticed they were broken.)
1 parent 0a2a59f commit 3fd8c70

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/type-checker.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ std::string TypesToString(const TypeVector& types,
3030
}
3131

3232
for (size_t i = 0; i < types.size(); ++i) {
33-
result += types[i].GetName();
33+
Type ty = types[i];
34+
// NOTE: Reference (and GetName) is also used by (e.g.) objdump, which does
35+
// not apply validation. do this here so as to not break that.
36+
if (ty == Type::Reference && ty.GetReferenceIndex() == kInvalidIndex) {
37+
result += "reference";
38+
} else {
39+
result += types[i].GetName();
40+
}
3441
if (i < types.size() - 1) {
3542
result += ", ";
3643
}
@@ -812,18 +819,10 @@ Result TypeChecker::OnRefNullExpr(Type type) {
812819
Result TypeChecker::OnRefIsNullExpr() {
813820
Type type;
814821
Result result = PeekType(0, &type);
815-
if (!(type == Type::Any || type.IsRef())) {
816-
TypeVector actual;
817-
if (Succeeded(result)) {
818-
actual.push_back(type);
819-
}
820-
std::string message =
821-
"type mismatch in ref.is_null, expected reference but got " +
822-
TypesToString(actual);
823-
PrintError("%s", message.c_str());
824-
result = Result::Error;
822+
if (!type.IsRef()) {
823+
type = Type::Reference;
825824
}
826-
result |= DropTypes(1);
825+
result |= PopAndCheck1Type(type, "ref.is_null");
827826
PushType(Type::I32);
828827
return result;
829828
}

test/spec/ref_is_null.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
init(externref:1) =>
55
deinit() =>
66
out/test/spec/ref_is_null.wast:52: assert_invalid passed:
7-
out/test/spec/ref_is_null/ref_is_null.1.wasm:000001b: error: type mismatch in ref.is_null, expected reference but got [i32]
7+
out/test/spec/ref_is_null/ref_is_null.1.wasm:000001b: error: type mismatch in ref.is_null, expected [reference] but got [i32]
88
000001b: error: OnRefIsNullExpr callback failed
99
out/test/spec/ref_is_null.wast:56: assert_invalid passed:
10+
out/test/spec/ref_is_null/ref_is_null.2.wasm:0000018: error: type mismatch in ref.is_null, expected [reference] but got []
1011
0000018: error: OnRefIsNullExpr callback failed
1112
16/16 tests passed.
1213
;;; STDOUT ;;)

0 commit comments

Comments
 (0)