Make sure we only open up closed tag unions

This commit is contained in:
Ayaz Hafiz 2022-04-21 09:19:17 -04:00
parent 633bdd5520
commit 188bd33f1f
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58

View file

@ -1183,24 +1183,25 @@ fn solve(
let actual =
either_type_index_to_var(constraints, subs, rank, pools, aliases, *type_index);
// let content = subs.get_content_without_compacting(actual);
// let fmt = roc_types::subs::SubsFmtContent(&content, subs);
let mut stack = vec![actual];
while let Some(var) = stack.pop() {
use {Content::*, FlatType::*};
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, desc.rank);
let new_union = Content::Structure(FlatType::TagUnion(tags, new_ext));
desc.content = new_union;
subs.set(var, desc);
Structure(TagUnion(tags, ext)) => {
match subs.get_content_without_compacting(ext) {
Structure(FlatType::EmptyTagUnion) => {
let new_ext = subs.fresh_unnamed_flex_var();
subs.set_rank(new_ext, desc.rank);
let new_union = Structure(TagUnion(tags, new_ext));
desc.content = new_union;
subs.set(var, desc);
}
_ => {}
}
// Also open up all nested tag unions.
let all_vars = tags.variables().into_iter();
stack.extend(
all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]),