Skip to content

Clarify arity mismatch message #7709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 @{<info>%s@} %s, but got @{<error>%s@}"
fprintf ppf
"This function is expected to have @{<info>%s@} %s, but%s has @{<error>%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 *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
1 │ Belt.Array.map([], (a, b) => 1)
2 │

This function expected 1 argument, but got 2
This function is expected to have 1 argument, but has 2
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
3 │ let z1 = expectCurried((x, y) => x + y)
4 │

This function expected 1 argument, but got 2
This function is expected to have 1 argument, but has 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let f = (cb: (int, int) => int): string => {
ignore(cb)
"hello"
}

let x = f(_a => "hello")