From 1076a1bfe62865cc6d9f072808a1e11b9c184b9c Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 3 Dec 2024 15:15:21 -0800 Subject: [PATCH 1/3] Add some tests for invalid subtyping due to non-matching field types Specifically around the requirements that both field types have the same mutability and that the storage type must be exactly the same when the field type is mutable. --- test/core/gc/type-subtyping-invalid.wast | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/core/gc/type-subtyping-invalid.wast diff --git a/test/core/gc/type-subtyping-invalid.wast b/test/core/gc/type-subtyping-invalid.wast new file mode 100644 index 000000000..3b4c74357 --- /dev/null +++ b/test/core/gc/type-subtyping-invalid.wast @@ -0,0 +1,37 @@ +(assert_invalid + (module + ;; When fields are mutable, a subtype's reference fields cannot be subtypes of + ;; the supertype's fields, they must match exactly. + (type $a (sub (struct (field (mut (ref null any)))))) + (type $b (sub $a (struct (field (mut (ref null none)))))) + ) + "sub type 1 does not match super type" +) + +(assert_invalid + (module + ;; When fields are const, a subtype's reference fields cannot be supertypes of + ;; the supertype's fields, they must be subtypes. + (type $a (sub (struct (field (mut (ref null none)))))) + (type $b (sub $a (struct (field (mut (ref null any)))))) + ) + "sub type 1 does not match super type" + ) + +(assert_invalid + (module + ;; The mutability of fields must be the same. + (type $c (sub (struct (field (mut (ref null any)))))) + (type $d (sub $c (struct (field (ref null none))))) + ) + "sub type 1 does not match super type" +) + +(assert_invalid + (module + ;; The mutability of fields must be the same. + (type $c (sub (struct (field (ref null any))))) + (type $d (sub $c (struct (field (mut (ref null none)))))) + ) + "sub type 1 does not match super type" +) From 2b4087abbffc02429e463b6843e5825e72e0a8e2 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Wed, 4 Dec 2024 08:55:54 -0800 Subject: [PATCH 2/3] Use the same storage types for mut and non-mut field-matching tests --- test/core/gc/type-subtyping-invalid.wast | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/core/gc/type-subtyping-invalid.wast b/test/core/gc/type-subtyping-invalid.wast index 3b4c74357..d5b66ee37 100644 --- a/test/core/gc/type-subtyping-invalid.wast +++ b/test/core/gc/type-subtyping-invalid.wast @@ -19,19 +19,19 @@ ) (assert_invalid - (module - ;; The mutability of fields must be the same. - (type $c (sub (struct (field (mut (ref null any)))))) - (type $d (sub $c (struct (field (ref null none))))) + (module + ;; The mutability of fields must be the same. + (type $c (sub (struct (field (mut (ref null any)))))) + (type $d (sub $c (struct (field (ref null any))))) ) "sub type 1 does not match super type" ) (assert_invalid - (module - ;; The mutability of fields must be the same. - (type $c (sub (struct (field (ref null any))))) - (type $d (sub $c (struct (field (mut (ref null none)))))) + (module + ;; The mutability of fields must be the same. + (type $c (sub (struct (field (ref null any))))) + (type $d (sub $c (struct (field (mut (ref null any)))))) ) "sub type 1 does not match super type" ) From f8b9750edd0816f90ca419ed512d1ec45f7b3dd2 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Wed, 4 Dec 2024 10:54:21 -0800 Subject: [PATCH 3/3] Fix copy-paste bug --- test/core/gc/type-subtyping-invalid.wast | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/core/gc/type-subtyping-invalid.wast b/test/core/gc/type-subtyping-invalid.wast index d5b66ee37..d0442e247 100644 --- a/test/core/gc/type-subtyping-invalid.wast +++ b/test/core/gc/type-subtyping-invalid.wast @@ -12,8 +12,8 @@ (module ;; When fields are const, a subtype's reference fields cannot be supertypes of ;; the supertype's fields, they must be subtypes. - (type $a (sub (struct (field (mut (ref null none)))))) - (type $b (sub $a (struct (field (mut (ref null any)))))) + (type $a (sub (struct (field (ref null none))))) + (type $b (sub $a (struct (field (ref null any))))) ) "sub type 1 does not match super type" )