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)
}

View File

@ -0,0 +1,16 @@
# +opt infer:print_only_under_alias
app "test" provides [limitedKind] to "./platform"
Kind : [ A, B, C ]
Data : {kind: Kind}
limitedKind : Data -> Str
limitedKind = \data ->
when data is
# ^^^^ { kind : [A, B, C] }
{kind: A} -> "A is special"
{kind} -> when kind is
B -> "B"
C -> "C"
_ -> ""