summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm/wasm-validator.cpp19
-rw-r--r--test/spec/struct.wast26
2 files changed, 36 insertions, 9 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 14955ecae..425792e22 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -2302,16 +2302,17 @@ void FunctionValidator::visitStructNew(StructNew* curr) {
"struct.new_with_default value type must be defaultable");
}
} else {
- shouldBeEqual(curr->operands.size(),
- fields.size(),
- curr,
- "struct.new must have the right number of operands");
- // All the fields must have the proper type.
- for (Index i = 0; i < fields.size(); i++) {
- shouldBeSubType(curr->operands[i]->type,
- fields[i].type,
+ if (shouldBeEqual(curr->operands.size(),
+ fields.size(),
curr,
- "struct.new operand must have proper type");
+ "struct.new must have the right number of operands")) {
+ // All the fields must have the proper type.
+ for (Index i = 0; i < fields.size(); i++) {
+ shouldBeSubType(curr->operands[i]->type,
+ fields[i].type,
+ curr,
+ "struct.new operand must have proper type");
+ }
}
}
}
diff --git a/test/spec/struct.wast b/test/spec/struct.wast
index 20f5a0d63..bac4d4520 100644
--- a/test/spec/struct.wast
+++ b/test/spec/struct.wast
@@ -105,3 +105,29 @@
)
"invalid rtt"
)
+
+(assert_invalid
+ (module
+ (type $vec (struct (field i32)))
+ (func $test
+ (drop
+ ;; too many arguments
+ (struct.new_with_rtt $vec (i32.const 1) (i32.const 2) (rtt.canon $vec))
+ )
+ )
+ )
+ "invalid number of arguments to struct.new"
+)
+
+(assert_invalid
+ (module
+ (type $vec (struct (field i32) (field i32)))
+ (func $test
+ (drop
+ ;; too few arguments
+ (struct.new_with_rtt $vec (i32.const 1) (rtt.canon $vec))
+ )
+ )
+ )
+ "invalid number of arguments to struct.new"
+)