diff --git a/CHANGELOG.md b/CHANGELOG.md index 904ee3fc53..04f7e10e90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Configuration fields `bs-dependencies`, `bs-dev-dependencies` and `bsc-flags` are now deprecated in favor of `dependencies`, `dev-dependencies` and `compiler-flags`. https://github.com/rescript-lang/rescript/pull/7658 - Better error message if platform binaries package is not found. https://github.com/rescript-lang/rescript/pull/7698 +- Polish arity mismatch error message a bit. https://github.com/rescript-lang/rescript/pull/7709 #### :house: Internal diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index a23ca6e8aa..feff8336c2 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -794,9 +794,11 @@ let print_expr_type_clash ~context env loc trace ppf = show_extra_help ppf env trace let report_arity_mismatch ~arity_a ~arity_b ppf = - fprintf ppf "This function expected @{%s@} %s, but got @{%s@}" + fprintf ppf + "This function is expected to have @{%s@} %s, but%s has @{%s@}" arity_b (if arity_b = "1" then "argument" else "arguments") + (if int_of_string arity_a < int_of_string arity_b then " only" else "") arity_a (* Records *) diff --git a/tests/build_tests/super_errors/expected/arity_mismatch3.res.expected b/tests/build_tests/super_errors/expected/arity_mismatch3.res.expected index 8d09a697d6..e17f309c3a 100644 --- a/tests/build_tests/super_errors/expected/arity_mismatch3.res.expected +++ b/tests/build_tests/super_errors/expected/arity_mismatch3.res.expected @@ -5,4 +5,4 @@ 1 │ Belt.Array.map([], (a, b) => 1) 2 │ - This function expected 1 argument, but got 2 \ No newline at end of file + This function is expected to have 1 argument, but has 2 \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/arity_mismatch_fewer.res.expected b/tests/build_tests/super_errors/expected/arity_mismatch_fewer.res.expected new file mode 100644 index 0000000000..d9e9578c42 --- /dev/null +++ b/tests/build_tests/super_errors/expected/arity_mismatch_fewer.res.expected @@ -0,0 +1,10 @@ + + We've found a bug for you! + /.../fixtures/arity_mismatch_fewer.res:6:11-23 + + 4 │ } + 5 │ + 6 │ let x = f(_a => "hello") + 7 │ + + This function is expected to have 2 arguments, but only has 1 \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/curried_expected.res.expected b/tests/build_tests/super_errors/expected/curried_expected.res.expected index 79438d1b9d..7afa86e262 100644 --- a/tests/build_tests/super_errors/expected/curried_expected.res.expected +++ b/tests/build_tests/super_errors/expected/curried_expected.res.expected @@ -7,4 +7,4 @@ 3 │ let z1 = expectCurried((x, y) => x + y) 4 │ - This function expected 1 argument, but got 2 \ No newline at end of file + This function is expected to have 1 argument, but has 2 \ No newline at end of file diff --git a/tests/build_tests/super_errors/fixtures/arity_mismatch_fewer.res b/tests/build_tests/super_errors/fixtures/arity_mismatch_fewer.res new file mode 100644 index 0000000000..6caf5c9c13 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/arity_mismatch_fewer.res @@ -0,0 +1,6 @@ +let f = (cb: (int, int) => int): string => { + ignore(cb) + "hello" +} + +let x = f(_a => "hello")