summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r--src/wasm/wasm-s-parser.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 507cf3b6c..98f7c1e87 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -2783,13 +2783,25 @@ Expression* SExpressionWasmBuilder::makeRefTest(Element& s) {
Expression* SExpressionWasmBuilder::makeRefCast(Element& s) {
int i = 1;
+ std::optional<Nullability> nullability;
if (s[0]->str().str != "ref.cast_static") {
- if (s[i++]->str().str != "null") {
- throw ParseException("ref.cast not yet supported. Use ref.cast null.");
+ nullability = NonNullable;
+ if (s[i]->str().str == "null") {
+ nullability = Nullable;
+ ++i;
}
}
auto heapType = parseHeapType(*s[i++]);
auto* ref = parseExpression(*s[i++]);
+ if (nullability && ref->type.isRef()) {
+ if (*nullability == NonNullable && ref->type.isNullable()) {
+ throw ParseException(
+ "ref.cast on nullable input not yet supported", s.line, s.col);
+ } else if (*nullability == Nullable && ref->type.isNonNullable()) {
+ throw ParseException(
+ "ref.cast null on non-nullable input not yet supported", s.line, s.col);
+ }
+ }
return Builder(wasm).makeRefCast(ref, heapType, RefCast::Safe);
}