feat(unify): Func, TagUnion add the other way

This commit is contained in:
rvcas 2021-03-21 00:28:52 -04:00
parent 7f7386c639
commit 3098bcf61d

View file

@ -1104,8 +1104,40 @@ fn unify_flat_type(
) )
} }
} }
(Func(_args, _closure, _ret), TagUnion(tags, _ext)) if tags.len() == 1 => { (Func(args, closure, ret), TagUnion(tags, ext)) if tags.len() == 1 => {
todo!("other way") let (tag, payload) = tags.iter().next().unwrap();
if payload.is_empty() {
let mut new_payload = vec![];
let mut new_tags = MutMap::default();
for arg in args {
new_payload.push(*arg);
}
new_tags.insert(tag.clone(), new_payload);
let content = Structure(TagUnion(new_tags, *ext));
let new_tag_union_var = fresh(subs, pool, ctx, content);
let problems = unify_pool(subs, pool, *ret, new_tag_union_var);
if problems.is_empty() {
let desc = subs.get(ctx.second);
subs.union(ctx.first, ctx.second, desc);
vec![]
} else {
problems
}
} else {
mismatch!(
"Trying to unify two flat types that are incompatible: {:?} ~ {:?}",
Func(args.clone(), closure.clone(), ret.clone()),
TagUnion(tags.clone(), ext.clone()),
)
}
} }
(other1, other2) => mismatch!( (other1, other2) => mismatch!(
"Trying to unify two flat types that are incompatible: {:?} ~ {:?}", "Trying to unify two flat types that are incompatible: {:?} ~ {:?}",