diff --git a/CHANGELOG.md b/CHANGELOG.md index 811f920637..7da316df0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/build_tests/super_errors/expected/arity_mismatch.res.expected b/jscomp/build_tests/super_errors/expected/arity_mismatch.res.expected index ad2b681bc0..847488a6ea 100644 --- a/jscomp/build_tests/super_errors/expected/arity_mismatch.res.expected +++ b/jscomp/build_tests/super_errors/expected/arity_mismatch.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/arity_mismatch2.res.expected b/jscomp/build_tests/super_errors/expected/arity_mismatch2.res.expected index 0d12df304a..3eb99fe236 100644 --- a/jscomp/build_tests/super_errors/expected/arity_mismatch2.res.expected +++ b/jscomp/build_tests/super_errors/expected/arity_mismatch2.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/method_arity_mismatch.res.expected b/jscomp/build_tests/super_errors/expected/method_arity_mismatch.res.expected index 7ccb8b108a..fd3720d4ef 100644 --- a/jscomp/build_tests/super_errors/expected/method_arity_mismatch.res.expected +++ b/jscomp/build_tests/super_errors/expected/method_arity_mismatch.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/moreArguments1.res.expected b/jscomp/build_tests/super_errors/expected/moreArguments1.res.expected index 1333abc19f..7741f1c020 100644 --- a/jscomp/build_tests/super_errors/expected/moreArguments1.res.expected +++ b/jscomp/build_tests/super_errors/expected/moreArguments1.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/moreArguments2.res.expected b/jscomp/build_tests/super_errors/expected/moreArguments2.res.expected index e12c5afbb1..4ce85c8818 100644 --- a/jscomp/build_tests/super_errors/expected/moreArguments2.res.expected +++ b/jscomp/build_tests/super_errors/expected/moreArguments2.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/moreArguments3.res.expected b/jscomp/build_tests/super_errors/expected/moreArguments3.res.expected index a33272f9f8..bb9eec13f8 100644 --- a/jscomp/build_tests/super_errors/expected/moreArguments3.res.expected +++ b/jscomp/build_tests/super_errors/expected/moreArguments3.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/moreArguments4.res.expected b/jscomp/build_tests/super_errors/expected/moreArguments4.res.expected index 449bdf8315..ac90eb4320 100644 --- a/jscomp/build_tests/super_errors/expected/moreArguments4.res.expected +++ b/jscomp/build_tests/super_errors/expected/moreArguments4.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/moreArguments5.res.expected b/jscomp/build_tests/super_errors/expected/moreArguments5.res.expected index 0f17c3913e..0def8a7959 100644 --- a/jscomp/build_tests/super_errors/expected/moreArguments5.res.expected +++ b/jscomp/build_tests/super_errors/expected/moreArguments5.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/partial_app.res.expected b/jscomp/build_tests/super_errors/expected/partial_app.res.expected index de2121de51..7b57e9dee5 100644 --- a/jscomp/build_tests/super_errors/expected/partial_app.res.expected +++ b/jscomp/build_tests/super_errors/expected/partial_app.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/primitives3.res.expected b/jscomp/build_tests/super_errors/expected/primitives3.res.expected index 6092fdf01b..55bc7744e7 100644 --- a/jscomp/build_tests/super_errors/expected/primitives3.res.expected +++ b/jscomp/build_tests/super_errors/expected/primitives3.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/recursive_type.res.expected b/jscomp/build_tests/super_errors/expected/recursive_type.res.expected index 3abe6f067b..714cd2e515 100644 --- a/jscomp/build_tests/super_errors/expected/recursive_type.res.expected +++ b/jscomp/build_tests/super_errors/expected/recursive_type.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/warnings1.res.expected b/jscomp/build_tests/super_errors/expected/warnings1.res.expected index 5a0d1c5d76..3916a8625b 100644 --- a/jscomp/build_tests/super_errors/expected/warnings1.res.expected +++ b/jscomp/build_tests/super_errors/expected/warnings1.res.expected @@ -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. \ No newline at end of file diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index fc502f263e..bdb8a137e4 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -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 "@[@[<2>This uncurried function has type@ %a@]" + fprintf ppf "@[@[<2>This function has type@ %a@]" type_expr typ; fprintf ppf "@ @[It is applied with @{%d@} argument%s but it requires @{%d@}.@]@]" args (if args = 0 then "" else "s") arity