Skip to content

Commit

Permalink
Add reporting tests for annotated functions with early returns
Browse files Browse the repository at this point in the history
  • Loading branch information
smores56 committed Nov 21, 2024
1 parent f857872 commit 899a7d3
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions crates/compiler/load/tests/test_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 899a7d3

Please sign in to comment.