mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Make sure we only open up closed tag unions
This commit is contained in:
parent
633bdd5520
commit
188bd33f1f
1 changed files with 14 additions and 13 deletions
|
@ -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]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue