diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 5cee9a52a6..4f0b7ef1fe 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -1994,7 +1994,15 @@ pub fn union_sorted_tags<'a>( let mut tags_vec = std::vec::Vec::new(); let result = match roc_types::pretty_print::chase_ext_tag_union(subs, var, &mut tags_vec) { - Ok(()) | Err((_, Content::FlexVar(_))) | Err((_, Content::RecursionVar { .. })) => { + Ok(()) + // Admit type variables in the extension for now. This may come from things that never got + // monomorphized, like in + // x : [ 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::RecursionVar { .. })) => { let opt_rec_var = get_recursion_var(subs, var); union_sorted_tags_help(arena, tags_vec, opt_rec_var, subs, target_info) } @@ -2592,7 +2600,7 @@ 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(_))) => ext_fields.is_empty(), + Ok(()) | Err((_, Content::FlexVar(_) | Content::RigidVar(_))) => ext_fields.is_empty(), Err(content) => panic!("invalid content in ext_var: {:?}", content), } } diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index 4cab64ec87..8a5e2d276a 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1548,3 +1548,19 @@ fn issue_1162() { u8 ) } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn polymorphic_tag() { + assert_evals_to!( + indoc!( + r#" + x : [ Y U8 ]* + x = Y 3 + x + "# + ), + 3, // Y is a newtype, it gets unwrapped + u8 + ) +}