mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
IsOpen constraints should always open up all nested tag unions
This commit is contained in:
parent
04d1025b2d
commit
115cd2ba75
1 changed files with 31 additions and 18 deletions
|
@ -1183,15 +1183,26 @@ fn solve(
|
|||
let actual =
|
||||
either_type_index_to_var(constraints, subs, rank, pools, aliases, *type_index);
|
||||
|
||||
let mut new_desc = subs.get(actual);
|
||||
match new_desc.content {
|
||||
Content::Structure(FlatType::TagUnion(tags, _)) => {
|
||||
let mut stack = vec![actual];
|
||||
while let Some(var) = stack.pop() {
|
||||
let mut desc = subs.get(var);
|
||||
match desc.content {
|
||||
Content::Structure(FlatType::TagUnion(tags, ext))
|
||||
if matches!(
|
||||
subs.get_content_without_compacting(ext),
|
||||
Content::Structure(FlatType::EmptyTagUnion)
|
||||
) =>
|
||||
{
|
||||
let new_ext = subs.fresh_unnamed_flex_var();
|
||||
subs.set_rank(new_ext, new_desc.rank);
|
||||
subs.set_rank(new_ext, desc.rank);
|
||||
let new_union = Content::Structure(FlatType::TagUnion(tags, new_ext));
|
||||
new_desc.content = new_union;
|
||||
subs.set(actual, new_desc);
|
||||
state
|
||||
desc.content = new_union;
|
||||
subs.set(var, desc);
|
||||
|
||||
let all_vars = tags.variables().into_iter();
|
||||
stack.extend(
|
||||
all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]),
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
// Today, an "open" constraint doesn't affect any types
|
||||
|
@ -1200,10 +1211,12 @@ fn solve(
|
|||
// resolved), so that's not handled here either.
|
||||
// NB: Handle record types here if we add presence constraints
|
||||
// to their type inference as well.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
IncludesTag(index) => {
|
||||
let includes_tag = &constraints.includes_tags[index.index()];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue