From ea2357670a6cb2a41c6704dba06b2eb967fbe979 Mon Sep 17 00:00:00 2001 From: Maksim Volkau Date: Tue, 14 May 2024 21:13:38 +0200 Subject: [PATCH 1/2] feat: better error msg --- crates/compiler/load/tests/test_reporting.rs | 24 +++++++++++++++----- crates/repl_test/src/tests.rs | 8 +++++-- crates/reporting/src/error/type.rs | 4 ++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/compiler/load/tests/test_reporting.rs b/crates/compiler/load/tests/test_reporting.rs index bbda53a5217..7fa724d357d 100644 --- a/crates/compiler/load/tests/test_reporting.rs +++ b/crates/compiler/load/tests/test_reporting.rs @@ -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: @@ -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!( @@ -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: @@ -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!( @@ -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: @@ -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 ", " + "# ); } diff --git a/crates/repl_test/src/tests.rs b/crates/repl_test/src/tests.rs index 7099e22f19d..ed43a993181 100644 --- a/crates/repl_test/src/tests.rs +++ b/crates/repl_test/src/tests.rs @@ -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: @@ -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 ", " + "# ), ); } diff --git a/crates/reporting/src/error/type.rs b/crates/reporting/src/error/type.rs index e8313466217..8e839e0ef11 100644 --- a/crates/reporting/src/error/type.rs +++ b/crates/reporting/src/error/type.rs @@ -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 { From f6b30a1be7c794de2c793d43997b62604001449c Mon Sep 17 00:00:00 2001 From: Maksim Volkau Date: Tue, 23 Jul 2024 11:30:29 +0200 Subject: [PATCH 2/2] Revert "feat: better error msg" This reverts commit ea2357670a6cb2a41c6704dba06b2eb967fbe979. --- crates/compiler/load/tests/test_reporting.rs | 24 +++++--------------- crates/repl_test/src/tests.rs | 8 ++----- crates/reporting/src/error/type.rs | 4 ---- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/crates/compiler/load/tests/test_reporting.rs b/crates/compiler/load/tests/test_reporting.rs index da99ad1faf6..71418e4288c 100644 --- a/crates/compiler/load/tests/test_reporting.rs +++ b/crates/compiler/load/tests/test_reporting.rs @@ -1666,7 +1666,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: @@ -1676,11 +1676,7 @@ 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!( @@ -14475,7 +14471,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: @@ -14485,11 +14481,7 @@ 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!( @@ -14499,7 +14491,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: @@ -14509,10 +14501,6 @@ 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 ", " - "# + " ); } diff --git a/crates/repl_test/src/tests.rs b/crates/repl_test/src/tests.rs index a0e344ec678..5aae4e2e1dc 100644 --- a/crates/repl_test/src/tests.rs +++ b/crates/repl_test/src/tests.rs @@ -647,7 +647,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: @@ -657,11 +657,7 @@ 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 ", " - "# + " ), ); } diff --git a/crates/reporting/src/error/type.rs b/crates/reporting/src/error/type.rs index 85a8fa104c4..b13c24781cc 100644 --- a/crates/reporting/src/error/type.rs +++ b/crates/reporting/src/error/type.rs @@ -1250,10 +1250,6 @@ 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 {