mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
Mark named destructures under records as open
This commit is contained in:
parent
9b58c0fb9c
commit
815ae5df9d
@ -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)
|
||||
}
|
||||
|
@ -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"
|
||||
_ -> ""
|
Loading…
Reference in New Issue
Block a user