Expose type mismatches between recursive types and types that aren't

Closes #2166
This commit is contained in:
ayazhafiz 2022-01-30 00:21:45 -05:00
parent ee05d13802
commit e54917a063
2 changed files with 43 additions and 1 deletions

View file

@ -285,7 +285,12 @@ fn unify_structure(
// unify the structure with this unrecursive tag union // unify the structure with this unrecursive tag union
unify_pool(subs, pool, ctx.first, *structure, ctx.mode) unify_pool(subs, pool, ctx.first, *structure, ctx.mode)
} }
_ => todo!("rec structure {:?}", &flat_type), // Only tag unions can be recursive; everything else is an error.
_ => mismatch!(
"trying to unify {:?} with recursive type var {:?}",
&flat_type,
structure
),
}, },
Structure(ref other_flat_type) => { Structure(ref other_flat_type) => {

View file

@ -7201,4 +7201,41 @@ I need all branches in an `if` to have the same type!
), ),
) )
} }
#[test]
fn unify_recursive_with_nonrecursive() {
report_problem_as(
indoc!(
r#"
Job : [ @Job { inputs : List Job } ]
job : { inputs : List Str } -> Job
job = \{ inputs } ->
@Job { inputs }
job { inputs: [ "build", "test" ] }
"#
),
indoc!(
r#"
TYPE MISMATCH
Something is off with the body of the `job` definition:
3 job : { inputs : List Str } -> Job
4 job = \{ inputs } ->
5 @Job { inputs }
^^^^^^^^^^^^^^^
This `@Job` private tag application has the type:
[ @Job { inputs : List Str } ]
But the type annotation on `job` says it should be:
[ @Job { inputs : List a } ] as a
"#
),
)
}
} }