-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
) |