mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Expose type mismatches between recursive types and types that aren't
Closes #2166
This commit is contained in:
parent
ee05d13802
commit
e54917a063
2 changed files with 43 additions and 1 deletions
|
@ -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) => {
|
||||||
|
|
|
@ -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
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue