diff --git a/CHANGELOG.md b/CHANGELOG.md index 7da3384db5..7b183c1ef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ - Make parser less strict around leading attributes. https://github.com/rescript-lang/rescript/pull/7787 - Dedicated error message for ternary type mismatch. https://github.com/rescript-lang/rescript/pull/7804 - Dedicated error message for passing a braced ident to something expected to be a record. https://github.com/rescript-lang/rescript/pull/7806 +- Hint about partial application when missing required argument in function call. https://github.com/rescript-lang/rescript/pull/7807 #### :house: Internal diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index 7882a07523..3ed7e59178 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -4667,12 +4667,18 @@ let report_error env loc ppf error = if not is_fallback then fprintf ppf "@,"; - if List.length missing_required_args > 0 then + if List.length missing_required_args > 0 then ( fprintf ppf "@,- Missing arguments that must be provided: %s" (missing_required_args |> List.map (fun v -> "~" ^ v) |> String.concat ", "); + fprintf ppf + "@,\ + - Hint: Did you want to partially apply the function? You can do that \ + by putting `...` just before the closing parens of the function call. \ + Example: @{yourFn(~arg1=someVar, ...)@}"); + if List.length superfluous_args > 0 then fprintf ppf "@,- Called with arguments it does not take: %s" (superfluous_args |> String.concat ", "); diff --git a/tests/build_tests/super_errors/expected/moreArguments1.res.expected b/tests/build_tests/super_errors/expected/moreArguments1.res.expected index 34bf4baf0e..1330d28720 100644 --- a/tests/build_tests/super_errors/expected/moreArguments1.res.expected +++ b/tests/build_tests/super_errors/expected/moreArguments1.res.expected @@ -10,4 +10,5 @@ The function has type: (~a: int, ~b: int) => int - - Missing arguments that must be provided: ~b \ No newline at end of file + - Missing arguments that must be provided: ~b + - Hint: Did you want to partially apply the function? You can do that by putting `...` just before the closing parens of the function call. Example: yourFn(~arg1=someVar, ...) \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/moreArguments4.res.expected b/tests/build_tests/super_errors/expected/moreArguments4.res.expected index f7bf2d1769..e15fcdc31e 100644 --- a/tests/build_tests/super_errors/expected/moreArguments4.res.expected +++ b/tests/build_tests/super_errors/expected/moreArguments4.res.expected @@ -10,4 +10,5 @@ The function has type: (int, ~b: int, ~c: 'a, ~d: 'b) => int - - Missing arguments that must be provided: ~d, ~c, ~b \ No newline at end of file + - Missing arguments that must be provided: ~d, ~c, ~b + - Hint: Did you want to partially apply the function? You can do that by putting `...` just before the closing parens of the function call. Example: yourFn(~arg1=someVar, ...) \ No newline at end of file