Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 1076a1b

Browse files
committed
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.
1 parent 88463e8 commit 1076a1b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(assert_invalid
2+
(module
3+
;; When fields are mutable, a subtype's reference fields cannot be subtypes of
4+
;; the supertype's fields, they must match exactly.
5+
(type $a (sub (struct (field (mut (ref null any))))))
6+
(type $b (sub $a (struct (field (mut (ref null none))))))
7+
)
8+
"sub type 1 does not match super type"
9+
)
10+
11+
(assert_invalid
12+
(module
13+
;; When fields are const, a subtype's reference fields cannot be supertypes of
14+
;; the supertype's fields, they must be subtypes.
15+
(type $a (sub (struct (field (mut (ref null none))))))
16+
(type $b (sub $a (struct (field (mut (ref null any))))))
17+
)
18+
"sub type 1 does not match super type"
19+
)
20+
21+
(assert_invalid
22+
(module
23+
;; The mutability of fields must be the same.
24+
(type $c (sub (struct (field (mut (ref null any))))))
25+
(type $d (sub $c (struct (field (ref null none)))))
26+
)
27+
"sub type 1 does not match super type"
28+
)
29+
30+
(assert_invalid
31+
(module
32+
;; The mutability of fields must be the same.
33+
(type $c (sub (struct (field (ref null any)))))
34+
(type $d (sub $c (struct (field (mut (ref null none))))))
35+
)
36+
"sub type 1 does not match super type"
37+
)

0 commit comments

Comments
 (0)