Mark named destructures under records as open

This commit is contained in:
Ayaz Hafiz 2023-05-24 12:59:31 -05:00
parent 9b58c0fb9c
commit 815ae5df9d
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 27 additions and 0 deletions

View file

@ -676,6 +676,17 @@ pub fn constrain_pattern(
RecordField::Optional(pat_type)
}
DestructType::Required => {
// Named destructures like
// {foo} -> ...
// are equivalent to wildcards on the type of `foo`, so if `foo` is a tag
// union, we must add a constraint to ensure that this destructure opens it
// up.
if could_be_a_tag_union(types, pat_type_index) {
state
.delayed_is_open_constraints
.push(constraints.is_open_type(pat_type_index));
}
// No extra constraints necessary.
RecordField::Demanded(pat_type)
}