mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
pull tags/fields from the ext_var during unification
This commit is contained in:
parent
9ef4a6d891
commit
a3b1ec3be0
4 changed files with 52 additions and 18 deletions
|
@ -320,7 +320,15 @@ fn unify_shared_fields(
|
|||
}
|
||||
|
||||
if num_shared_fields == matching_fields.len() {
|
||||
let flat_type = FlatType::Record(union(matching_fields, &other_fields), ext);
|
||||
// pull fields in from the ext_var
|
||||
let mut fields = union(matching_fields, &other_fields);
|
||||
|
||||
let new_ext_var = match roc_types::pretty_print::chase_ext_record(subs, ext, &mut fields) {
|
||||
Ok(()) => Variable::EMPTY_RECORD,
|
||||
Err((new, _)) => new,
|
||||
};
|
||||
|
||||
let flat_type = FlatType::Record(fields, new_ext_var);
|
||||
|
||||
merge(subs, ctx, Structure(flat_type))
|
||||
} else {
|
||||
|
@ -460,10 +468,21 @@ fn unify_shared_tags(
|
|||
}
|
||||
|
||||
if num_shared_tags == matching_tags.len() {
|
||||
// merge fields from the ext_var into this tag union
|
||||
let mut fields = Vec::new();
|
||||
let new_ext_var = match roc_types::pretty_print::chase_ext_tag_union(subs, ext, &mut fields)
|
||||
{
|
||||
Ok(()) => Variable::EMPTY_TAG_UNION,
|
||||
Err((new, _)) => new,
|
||||
};
|
||||
|
||||
let mut new_tags = union(matching_tags, &other_tags);
|
||||
new_tags.extend(fields.into_iter());
|
||||
|
||||
let flat_type = if let Some(rec) = recursion_var {
|
||||
FlatType::RecursiveTagUnion(rec, union(matching_tags, &other_tags), ext)
|
||||
FlatType::RecursiveTagUnion(rec, new_tags, new_ext_var)
|
||||
} else {
|
||||
FlatType::TagUnion(union(matching_tags, &other_tags), ext)
|
||||
FlatType::TagUnion(new_tags, new_ext_var)
|
||||
};
|
||||
|
||||
merge(subs, ctx, Structure(flat_type))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue