Skip to content

Commit

Permalink
feat: better error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed May 14, 2024
1 parent e5ea6dc commit ea23576
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
24 changes: 18 additions & 6 deletions crates/compiler/load/tests/test_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ mod test_reporting {
f 1
"
),
@r"
@r#"
── TOO FEW ARGS in /code/proj/Main.roc ─────────────────────────────────────────
The `f` function expects 2 arguments, but it got only 1:
Expand All @@ -1675,7 +1675,11 @@ mod test_reporting {
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
"
For example: ["a", "b"] |> \list -> Str.joinWith list ", "
or simplier: ["a", "b"] |> Str.joinWith ", "
"#
);

test_report!(
Expand Down Expand Up @@ -14214,7 +14218,7 @@ In roc, functions are always written as a lambda, like{}
2 |> (Num.sub 3)
"
),
@r"
@r#"
── TOO FEW ARGS in /code/proj/Main.roc ─────────────────────────────────────────
The `sub` function expects 2 arguments, but it got only 1:
Expand All @@ -14224,7 +14228,11 @@ In roc, functions are always written as a lambda, like{}
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
"
For example: ["a", "b"] |> \list -> Str.joinWith list ", "
or simplier: ["a", "b"] |> Str.joinWith ", "
"#
);

test_report!(
Expand All @@ -14234,7 +14242,7 @@ In roc, functions are always written as a lambda, like{}
2 |> (Num.sub 3) |> Num.sub 3
"
),
@r"
@r#"
── TOO FEW ARGS in /code/proj/Main.roc ─────────────────────────────────────────
The `sub` function expects 2 arguments, but it got only 1:
Expand All @@ -14244,6 +14252,10 @@ In roc, functions are always written as a lambda, like{}
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
"
For example: ["a", "b"] |> \list -> Str.joinWith list ", "
or simplier: ["a", "b"] |> Str.joinWith ", "
"#
);
}
8 changes: 6 additions & 2 deletions crates/repl_test/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ fn too_few_args() {
expect_failure(
"Num.add 2",
indoc!(
r"
r#"
── TOO FEW ARGS ────────────────────────────────────────────────────────────────
The add function expects 2 arguments, but it got only 1:
Expand All @@ -652,7 +652,11 @@ fn too_few_args() {
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
"
For example: ["a", "b"] |> \list -> Str.joinWith list ", "
or simplier: ["a", "b"] |> Str.joinWith ", "
"#
),
);
}
Expand Down
4 changes: 4 additions & 0 deletions crates/reporting/src/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,10 @@ fn to_expr_report<'b>(
"Roc does not allow functions to be partially applied. \
Use a closure to make partial application explicit.",
),
alloc.reflow(
r#"For example: ["a", "b"] |> \list -> Str.joinWith list ", ""#,
),
alloc.reflow(r#"or simplier: ["a", "b"] |> Str.joinWith ", ""#),
];

Report {
Expand Down

0 comments on commit ea23576

Please sign in to comment.