Print alias's underlying structures if OIOP vars are material

This commit is contained in:
Ayaz Hafiz 2022-10-26 15:52:50 -05:00
parent e1b6e0334b
commit 9854f5f2ac
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
3 changed files with 49 additions and 4 deletions

View File

@ -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]*
"###
);
}
}

View File

@ -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);

View File

@ -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 {