Merge pull request #3835 from roc-lang/ext-vars-in-derivers

Support bound and unbound extension variables in deriving
This commit is contained in:
Folkert de Vries 2022-08-30 00:34:50 +02:00 committed by GitHub
commit acb71d6007
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 202 additions and 61 deletions

View file

@ -2728,7 +2728,7 @@ pub fn union_sorted_tags<'a>(
// x = A
// x
// In such cases it's fine to drop the variable. We may be proven wrong in the future...
| Err((_, Content::FlexVar(_) | Content::RigidVar(_)))
| Err((_, Content::FlexVar(_) | Content::FlexAbleVar(..) | Content::RigidVar(_) | Content::RigidAbleVar(..)))
| Err((_, Content::RecursionVar { .. })) => {
let opt_rec_var = get_recursion_var(subs, var);
union_sorted_tags_help(arena, tags_vec, opt_rec_var, subs, target_info)
@ -3369,9 +3369,17 @@ pub fn ext_var_is_empty_tag_union(subs: &Subs, ext_var: Variable) -> bool {
// the ext_var is empty
let mut ext_fields = std::vec::Vec::new();
match roc_types::pretty_print::chase_ext_tag_union(subs, ext_var, &mut ext_fields) {
Ok(()) | Err((_, Content::FlexVar(_) | Content::RigidVar(_) | Content::Error)) => {
ext_fields.is_empty()
}
Ok(())
| Err((
_,
// Allow flex/rigid to decay away into nothing
Content::FlexVar(_)
| Content::FlexAbleVar(..)
| Content::RigidVar(_)
| Content::RigidAbleVar(..)
// So that we can continue compiling in the presence of errors
| Content::Error,
)) => ext_fields.is_empty(),
Err(content) => panic!("invalid content in ext_var: {:?}", content),
}
}