mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Merge remote-tracking branch 'remote/main' into rebuild-platform
This commit is contained in:
commit
c00db6da37
100 changed files with 2554 additions and 279 deletions
|
@ -14426,4 +14426,192 @@ All branches in an `if` must have the same type!
|
|||
// ),
|
||||
// @r""
|
||||
// );
|
||||
|
||||
test_report!(
|
||||
issue_6240_1,
|
||||
indoc!(
|
||||
r"
|
||||
{}.abcde
|
||||
"
|
||||
),
|
||||
@r###"
|
||||
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||
|
||||
This record doesn’t have a `abcde` field:
|
||||
|
||||
4│ {}.abcde
|
||||
^^^^^^^^
|
||||
|
||||
In fact, it’s a record with no fields at all!
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
issue_6240_2,
|
||||
indoc!(
|
||||
r#"
|
||||
("", "").abcde
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||
|
||||
This expression is used in an unexpected way:
|
||||
|
||||
4│ ("", "").abcde
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
It is a tuple of type:
|
||||
|
||||
(
|
||||
Str,
|
||||
Str,
|
||||
)a
|
||||
|
||||
But you are trying to use it as:
|
||||
|
||||
{ abcde : * }b
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
issue_6240_3,
|
||||
indoc!(
|
||||
r"
|
||||
{}.0
|
||||
"
|
||||
),
|
||||
@r###"
|
||||
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||
|
||||
This expression is used in an unexpected way:
|
||||
|
||||
4│ {}.0
|
||||
^^^^
|
||||
|
||||
It is a record of type:
|
||||
|
||||
{}
|
||||
|
||||
But you are trying to use it as:
|
||||
|
||||
(*)b
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
return_outside_of_function,
|
||||
indoc!(
|
||||
r"
|
||||
someVal =
|
||||
if 10 > 5 then
|
||||
x = 5
|
||||
return x
|
||||
else
|
||||
6
|
||||
|
||||
someVal + 2
|
||||
"
|
||||
),
|
||||
@r###"
|
||||
── RETURN OUTSIDE OF FUNCTION in /code/proj/Main.roc ───────────────────────────
|
||||
|
||||
This `return` statement doesn't belong to a function:
|
||||
|
||||
7│ return x
|
||||
^^^^^^^^
|
||||
|
||||
I wouldn't know where to return to if I used it!
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
statements_after_return,
|
||||
indoc!(
|
||||
r#"
|
||||
myFunction = \x ->
|
||||
if x == 2 then
|
||||
return x
|
||||
|
||||
log! "someData"
|
||||
useX x 123
|
||||
else
|
||||
x + 5
|
||||
|
||||
myFunction 2
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
── UNREACHABLE CODE in /code/proj/Main.roc ─────────────────────────────────────
|
||||
|
||||
This code won't run because it follows a `return` statement:
|
||||
|
||||
6│> return x
|
||||
7│>
|
||||
8│> log! "someData"
|
||||
9│> useX x 123
|
||||
|
||||
Hint: you can move the `return` statement below this block to make the
|
||||
code that follows it run.
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
return_at_end_of_function,
|
||||
indoc!(
|
||||
r#"
|
||||
myFunction = \x ->
|
||||
y = Num.toStr x
|
||||
|
||||
return y
|
||||
|
||||
myFunction 3
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
── UNNECESSARY RETURN in /code/proj/Main.roc ───────────────────────────────────
|
||||
|
||||
This `return` keyword is redundant:
|
||||
|
||||
7│ return y
|
||||
^^^^^^^^
|
||||
|
||||
The last expression in a function is treated like a `return` statement.
|
||||
You can safely remove `return` here.
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
mismatch_early_return_with_function_output,
|
||||
indoc!(
|
||||
r#"
|
||||
myFunction = \x ->
|
||||
if x == 5 then
|
||||
return "abc"
|
||||
else
|
||||
x
|
||||
|
||||
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│ x
|
||||
|
||||
This returns a value of type:
|
||||
|
||||
Str
|
||||
|
||||
But I expected the function to have return type:
|
||||
|
||||
Num *
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue