Skip to content

Commit 69c8067

Browse files
committed
Fix arity error message with optional args.
Fixes #6637
1 parent d153a91 commit 69c8067

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

compiler/ml/typecore.ml

+8-7
Original file line numberDiff line numberDiff line change
@@ -3514,13 +3514,14 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
35143514
| Some arity ->
35153515
let newarity = arity - nargs in
35163516
let fully_applied = newarity <= 0 in
3517-
if total_app && not fully_applied then
3518-
raise
3519-
(Error
3520-
( funct.exp_loc,
3521-
env,
3522-
Uncurried_arity_mismatch
3523-
(funct.exp_type, arity, List.length sargs) ));
3517+
(if total_app && not fully_applied then
3518+
let required_args = List.length sargs in
3519+
raise
3520+
(Error
3521+
( funct.exp_loc,
3522+
env,
3523+
Uncurried_arity_mismatch
3524+
(funct.exp_type, required_args + newarity, required_args) )));
35243525
let new_t =
35253526
if fully_applied then new_t
35263527
else
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/opt_args_arity.res:2:9
4+
5+
1 │ let f = (~a=0, b, c) => a + b + c
6+
2 │ let x = f(42)
7+
8+
This function has type (~a: int=?, int, int) => int
9+
It is applied with 1 arguments but it requires 2.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let f = (~a=0, b, c) => a + b + c
2+
let x = f(42)

0 commit comments

Comments
 (0)