Skip to content

Improve error messages for function arity errors #6990

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 2 commits into from
Aug 30, 2024
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 @@ -120,6 +120,7 @@
- Fix `Js.Types.JSBigInt` payload to use native `bigint` type. https://github.com/rescript-lang/rescript-compiler/pull/6911
- Deprecate `%external` extension, which has never been officially introduced. https://github.com/rescript-lang/rescript-compiler/pull/6906
- Deprecate `xxxU` functions in Belt. https://github.com/rescript-lang/rescript-compiler/pull/6941
- Improve error messages for function arity errors. https://github.com/rescript-lang/rescript-compiler/pull/6990

# 11.1.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
2 │ let makeVariables = makeVar(.~f=f => f)
3 │

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

This uncurried function has type ('a, unit) => int
This function has type ('a, unit) => int
It is applied with 3 arguments but it requires 2.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
4 │ }
5 │

This uncurried function has type (int, int) => unit
This function has type (int, int) => unit
It is applied with 1 arguments but it requires 2.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
2 │ let y = x(~a=2) + 2
3 │

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

This uncurried function has type (int, int) => int
This function has type (int, int) => int
It is applied with 1 arguments but it requires 2.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
2 │ let y = x(2) + 2
3 │

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

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

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

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

This uncurried function has type int => int
This function has type int => int
It is applied with 2 arguments but it requires 1.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
36 │ assert(false)
37 │ }

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

This uncurried function has type (int, int) => int
This function has type (int, int) => int
It is applied with 1 arguments but it requires 2.
2 changes: 1 addition & 1 deletion jscomp/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4011,7 +4011,7 @@ let report_error env ppf = function
| Empty_record_literal ->
fprintf ppf "Empty record literal {} should be type annotated or used in a record context."
| Uncurried_arity_mismatch (typ, arity, args) ->
fprintf ppf "@[<v>@[<2>This uncurried function has type@ %a@]"
fprintf ppf "@[<v>@[<2>This function has type@ %a@]"
type_expr typ;
fprintf ppf "@ @[It is applied with @{<error>%d@} argument%s but it requires @{<info>%d@}.@]@]"
args (if args = 0 then "" else "s") arity
Expand Down