IsOpen constraints should always open up all nested tag unions

This commit is contained in:
Ayaz Hafiz 2022-04-20 14:19:09 -04:00
parent 04d1025b2d
commit 115cd2ba75
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58

View file

@ -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()];