mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Add reporting tests for annotated functions with early returns
This commit is contained in:
parent
f857872903
commit
899a7d3308
1 changed files with 71 additions and 0 deletions
|
@ -14655,6 +14655,77 @@ All branches in an `if` must have the same type!
|
|||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
mismatch_only_early_returns,
|
||||
indoc!(
|
||||
r#"
|
||||
myFunction = \x ->
|
||||
if x == 5 then
|
||||
return "abc"
|
||||
else
|
||||
return 123
|
||||
|
||||
myFunction 3
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||
|
||||
This `return` statement doesn't match the return type of its enclosing
|
||||
function:
|
||||
|
||||
5│ if x == 5 then
|
||||
6│ return "abc"
|
||||
7│ else
|
||||
8│ return 123
|
||||
^^^^^^^^^^
|
||||
|
||||
This returns a value of type:
|
||||
|
||||
Num *
|
||||
|
||||
But I expected the function to have return type:
|
||||
|
||||
Str
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
mismatch_early_return_annotated_function,
|
||||
indoc!(
|
||||
r#"
|
||||
myFunction : U64 -> Str
|
||||
myFunction = \x ->
|
||||
if x == 5 then
|
||||
return 123
|
||||
else
|
||||
"abc"
|
||||
|
||||
myFunction 3
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||
|
||||
Something is off with the body of the `myFunction` definition:
|
||||
|
||||
4│ myFunction : U64 -> Str
|
||||
5│ myFunction = \x ->
|
||||
6│ if x == 5 then
|
||||
7│ return 123
|
||||
^^^^^^^^^^
|
||||
|
||||
This returns a value of type:
|
||||
|
||||
Num *
|
||||
|
||||
But the type annotation on `myFunction` says it should be:
|
||||
|
||||
Str
|
||||
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
leftover_statement,
|
||||
indoc!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue