Skip to content

Commit e8b4764

Browse files
authored
Clarify arity mismatch message (#7709)
* clarify arity mismatch message * explicitly call out supplying fewer arguments * changelog
1 parent 327b986 commit e8b4764

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
- 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
2727
- Better error message if platform binaries package is not found. https://github.com/rescript-lang/rescript/pull/7698
28+
- Polish arity mismatch error message a bit. https://github.com/rescript-lang/rescript/pull/7709
2829

2930
#### :house: Internal
3031

compiler/ml/typecore.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,11 @@ let print_expr_type_clash ~context env loc trace ppf =
794794
show_extra_help ppf env trace
795795

796796
let report_arity_mismatch ~arity_a ~arity_b ppf =
797-
fprintf ppf "This function expected @{<info>%s@} %s, but got @{<error>%s@}"
797+
fprintf ppf
798+
"This function is expected to have @{<info>%s@} %s, but%s has @{<error>%s@}"
798799
arity_b
799800
(if arity_b = "1" then "argument" else "arguments")
801+
(if int_of_string arity_a < int_of_string arity_b then " only" else "")
800802
arity_a
801803

802804
(* Records *)

tests/build_tests/super_errors/expected/arity_mismatch3.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
1 │ Belt.Array.map([], (a, b) => 1)
66
2 │
77

8-
This function expected 1 argument, but got 2
8+
This function is expected to have 1 argument, but has 2
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/arity_mismatch_fewer.res:6:11-23
4+
5+
4 │ }
6+
5 │
7+
6 │ let x = f(_a => "hello")
8+
7 │
9+
10+
This function is expected to have 2 arguments, but only has 1

tests/build_tests/super_errors/expected/curried_expected.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
3 │ let z1 = expectCurried((x, y) => x + y)
88
4 │
99

10-
This function expected 1 argument, but got 2
10+
This function is expected to have 1 argument, but has 2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let f = (cb: (int, int) => int): string => {
2+
ignore(cb)
3+
"hello"
4+
}
5+
6+
let x = f(_a => "hello")

0 commit comments

Comments
 (0)