Skip to content

Fix arity error message with optional args. #7284

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
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 9 additions & 8 deletions compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3514,13 +3514,14 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
| Some arity ->
let newarity = arity - nargs in
let fully_applied = newarity <= 0 in
if total_app && not fully_applied then
raise
(Error
( funct.exp_loc,
env,
Uncurried_arity_mismatch
(funct.exp_type, arity, List.length sargs) ));
(if total_app && not fully_applied then
let required_args = List.length sargs in
raise
(Error
( funct.exp_loc,
env,
Uncurried_arity_mismatch
(funct.exp_type, required_args + newarity, required_args) )));
let new_t =
if fully_applied then new_t
else
Expand Down Expand Up @@ -4463,7 +4464,7 @@ let report_error env ppf error =
"@ @[It is applied with @{<error>%d@} argument%s but it requires \
@{<info>%d@}.@]@]"
args
(if args = 0 then "" else "s")
(if args = 1 then "" else "s")
arity
| Field_not_optional (name, typ) ->
fprintf ppf "Field @{<info>%s@} is not optional in type %a. Use without ?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
3 │

This function has type (~f: 'a => 'a, unit) => int
It is applied with 1 arguments but it requires 2.
It is applied with 1 argument but it requires 2.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
5 │

This function has type (int, int) => unit
It is applied with 1 arguments but it requires 2.
It is applied with 1 argument but it requires 2.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
3 │

This function has type (~a: int, ~b: int) => int
It is applied with 1 arguments but it requires 2.
It is applied with 1 argument but it requires 2.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
3 │

This function has type (int, int) => int
It is applied with 1 arguments but it requires 2.
It is applied with 1 argument but it requires 2.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
3 │

This function has type (int, int, 'a, 'b) => int
It is applied with 1 arguments but it requires 4.
It is applied with 1 argument but it requires 4.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
3 │

This function has type (int, ~b: int, ~c: 'a, ~d: 'b) => int
It is applied with 1 arguments but it requires 4.
It is applied with 1 argument but it requires 4.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
6 │

This function has type (int, 'a, 'b, 'c) => Sub.a
It is applied with 1 arguments but it requires 4.
It is applied with 1 argument but it requires 4.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

We've found a bug for you!
/.../fixtures/opt_args_arity.res:2:9

1 │ let f = (~a=0, b, c) => a + b + c
2 │ let x = f(42)
3 │

This function has type (~a: int=?, int, int) => int
It is applied with 1 argument but it requires 2.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

This function has type
((option<'a>, ([> #List(list<'b>)] as 'b)) => 'c, 'd) => 'c
It is applied with 1 arguments but it requires 2.
It is applied with 1 argument but it requires 2.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
5 │ }

This function has type (int, int) => int
It is applied with 1 arguments but it requires 2.
It is applied with 1 argument but it requires 2.
2 changes: 2 additions & 0 deletions tests/build_tests/super_errors/fixtures/opt_args_arity.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let f = (~a=0, b, c) => a + b + c
let x = f(42)
Loading