Print recursion vars correctly

This commit is contained in:
Ayaz Hafiz 2022-05-10 10:40:37 -04:00
parent 7306e131b9
commit 3497237c99
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
8 changed files with 79 additions and 57 deletions

View file

@ -172,18 +172,12 @@ mod solve_expr {
let subs = solved.inner_mut();
// name type vars
for var in exposed_to_host.values() {
name_all_type_vars(*var, subs);
}
debug_assert!(exposed_to_host.len() == 1);
let (_symbol, variable) = exposed_to_host.into_iter().next().unwrap();
let named_result = name_all_type_vars(variable, subs);
let content = subs.get_content_without_compacting(variable);
let content = {
debug_assert!(exposed_to_host.len() == 1);
let (_symbol, variable) = exposed_to_host.into_iter().next().unwrap();
subs.get_content_without_compacting(variable)
};
let actual_str = content_to_string(content, subs, home, &interns);
let actual_str = content_to_string(content, subs, home, &interns, named_result);
Ok((type_problems, can_problems, actual_str))
}
@ -282,9 +276,9 @@ mod solve_expr {
let var = find_type_at(region, &decls)
.expect(&format!("No type for {} ({:?})!", &text, region));
name_all_type_vars(var, subs);
let named_result = name_all_type_vars(var, subs);
let content = subs.get_content_without_compacting(var);
let actual_str = content_to_string(content, subs, home, &interns);
let actual_str = content_to_string(content, subs, home, &interns, named_result);
solved_queries.push(format!("{} : {}", text, actual_str));
}
@ -5445,26 +5439,19 @@ mod solve_expr {
}
#[test]
fn copy_vars_referencing_copied_vars_specialized() {
fn generalize_and_specialize_recursion_var() {
infer_eq_without_problem(
indoc!(
r#"
Job a : [ Job [ Command ] (Job a) (List (Job a)) a ]
Job a : [ Job (List (Job a)) a ]
job : Job Str
when job is
Job _ j lst _ ->
when j is
Job _ _ _ s ->
{ j, lst, s }
Job lst s -> P lst s
"#
),
// TODO: this means that we're doing our job correctly, as now both `Job a`s have been
// specialized to the same type, and the second destructuring proves the reified type
// is `Job Str`. But we should just print the structure of the recursive type directly.
// See https://github.com/rtfeldman/roc/issues/2513
"{ j : a, lst : List a, s : Str }",
"[ P (List [ Job (List a) Str ] as a) Str ]*",
)
}