mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
parent
1d4e6acd41
commit
d4cf9b8f8d
2 changed files with 37 additions and 14 deletions
|
@ -1653,7 +1653,8 @@ fn open_tag_union(subs: &mut Subs, var: Variable) {
|
||||||
use {Content::*, FlatType::*};
|
use {Content::*, FlatType::*};
|
||||||
|
|
||||||
let desc = subs.get(var);
|
let desc = subs.get(var);
|
||||||
if let Structure(TagUnion(tags, ext)) = desc.content {
|
match desc.content {
|
||||||
|
Structure(TagUnion(tags, ext)) => {
|
||||||
if let Structure(EmptyTagUnion) = subs.get_content_without_compacting(ext) {
|
if let Structure(EmptyTagUnion) = subs.get_content_without_compacting(ext) {
|
||||||
let new_ext = subs.fresh_unnamed_flex_var();
|
let new_ext = subs.fresh_unnamed_flex_var();
|
||||||
subs.set_rank(new_ext, desc.rank);
|
subs.set_rank(new_ext, desc.rank);
|
||||||
|
@ -1666,12 +1667,21 @@ fn open_tag_union(subs: &mut Subs, var: Variable) {
|
||||||
stack.extend(all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]));
|
stack.extend(all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Structure(Record(fields, _)) => {
|
||||||
|
// Open up all nested tag unions.
|
||||||
|
stack.extend(subs.get_subs_slice(fields.variables()));
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {
|
||||||
|
// Everything else is not a structural type that can be opened
|
||||||
|
// (i.e. cannot be matched in a pattern-match)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Today, an "open" constraint doesn't affect any types
|
// Today, an "open" constraint doesn't affect any types
|
||||||
// other than tag unions. Recursive tag unions are constructed
|
// other than tag unions. Recursive tag unions are constructed
|
||||||
// at a later time (during occurs checks after tag unions are
|
// at a later time (during occurs checks after tag unions are
|
||||||
// resolved), so that's not handled here either.
|
// resolved), so that's not handled here either.
|
||||||
// NB: Handle record types here if we add presence constraints
|
|
||||||
// to their type inference as well.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7421,10 +7421,23 @@ mod solve_expr {
|
||||||
A _ C -> ""
|
A _ C -> ""
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
@r#"""
|
@r#"x : [A [B]* [C]*]"#
|
||||||
x : [A [B]* [C]*]
|
|
||||||
"""#
|
|
||||||
allow_errors: true
|
allow_errors: true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn catchall_branch_walk_into_nested_types() {
|
||||||
|
infer_queries!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
\x -> when x is
|
||||||
|
#^
|
||||||
|
{ a: A { b: B } } -> ""
|
||||||
|
_ -> ""
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
@r#"x : { a : [A { b : [B]* }*]* }*"#
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue