From cf96360aacd931d6016fa215bb3399421f300be5 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 24 Jul 2025 19:30:22 +0200 Subject: [PATCH 1/3] clarify arity mismatch message --- compiler/ml/typecore.ml | 3 ++- .../super_errors/expected/arity_mismatch3.res.expected | 2 +- .../super_errors/expected/curried_expected.res.expected | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index a23ca6e8aa..7bf30fb9f4 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -794,7 +794,8 @@ 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 has @{%s@}" arity_b (if arity_b = "1" then "argument" else "arguments") arity_a 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/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 From 7929b79db9c5262ff838064e0af22ecc70316114 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 24 Jul 2025 19:36:59 +0200 Subject: [PATCH 2/3] explicitly call out supplying fewer arguments --- compiler/ml/typecore.ml | 3 ++- .../expected/arity_mismatch_fewer.res.expected | 10 ++++++++++ .../super_errors/fixtures/arity_mismatch_fewer.res | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/build_tests/super_errors/expected/arity_mismatch_fewer.res.expected create mode 100644 tests/build_tests/super_errors/fixtures/arity_mismatch_fewer.res diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index 7bf30fb9f4..feff8336c2 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -795,9 +795,10 @@ let print_expr_type_clash ~context env loc trace ppf = let report_arity_mismatch ~arity_a ~arity_b ppf = fprintf ppf - "This function is expected to have @{%s@} %s, but has @{%s@}" + "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_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/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") From 4624817a2539767eb05828506f30b58d1449f8e8 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 24 Jul 2025 19:37:42 +0200 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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