mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
Print alias's underlying structures if OIOP vars are material
This commit is contained in:
parent
e1b6e0334b
commit
9854f5f2ac
@ -8167,4 +8167,33 @@ mod solve_expr {
|
||||
@"walkHelp {} : [Break [], Continue {}]"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contextual_openness_for_type_alias() {
|
||||
infer_queries!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [accum] to "./platform"
|
||||
|
||||
Q : [Green, Blue]
|
||||
|
||||
f : Q -> Q
|
||||
f = \q -> when q is
|
||||
#^{-1}
|
||||
Green -> Green
|
||||
Blue -> Blue
|
||||
|
||||
accum = \q -> when q is
|
||||
#^^^^^{-1}
|
||||
A -> f Green
|
||||
B -> Yellow
|
||||
C -> Orange
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
f : Q -[[f(2)]]-> Q
|
||||
accum : [A, B, C] -[[accum(0)]]-> [Blue, Green, Orange, Yellow]*
|
||||
"###
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -757,10 +757,16 @@ fn write_content<'a>(
|
||||
pol,
|
||||
),
|
||||
|
||||
_ if env.debug.print_only_under_alias => write_parens!(write_parens, buf, {
|
||||
let content = subs.get_content_without_compacting(*actual);
|
||||
write_content(env, ctx, content, subs, buf, parens, pol)
|
||||
}),
|
||||
_ if env.debug.print_only_under_alias
|
||||
// If any infer-open-in-output-position extension variable is now material, we
|
||||
// cannot keep the alias as-is - we have to print its underlying type!
|
||||
|| args.any_infer_ext_var_is_material(subs) =>
|
||||
{
|
||||
write_parens!(write_parens, buf, {
|
||||
let content = subs.get_content_without_compacting(*actual);
|
||||
write_content(env, ctx, content, subs, buf, parens, pol)
|
||||
})
|
||||
}
|
||||
|
||||
_ => write_parens!(write_parens, buf, {
|
||||
write_symbol(env, *symbol, buf);
|
||||
|
@ -2470,6 +2470,16 @@ impl AliasVariables {
|
||||
all_variables_len,
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks whether any inferred ext var in this alias has been resolved to a material type.
|
||||
pub fn any_infer_ext_var_is_material(&self, subs: &Subs) -> bool {
|
||||
subs.get_subs_slice(self.infer_ext_in_output_variables())
|
||||
.iter()
|
||||
.any(|v| match subs.get_content_unchecked(*v) {
|
||||
Content::FlexVar(None) | Content::Structure(FlatType::EmptyTagUnion) => false,
|
||||
_ => true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for AliasVariables {
|
||||
|
Loading…
Reference in New Issue
Block a user