diff --git a/CHANGELOG.md b/CHANGELOG.md index 35a9e57525..c2b2d765f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ - Fixed issue with coercions sometimes raising a `Not_found` instead of giving a proper error message. https://github.com/rescript-lang/rescript-compiler/pull/6574 - Fix issue with recursive modules and uncurried. https://github.com/rescript-lang/rescript-compiler/pull/6575 +#### :nail_care: Polish + +- Improve error message for missing label(s) in function application. https://github.com/rescript-lang/rescript-compiler/pull/6576 + # 11.0.0 No changes compared to rc.9. diff --git a/jscomp/build_tests/super_errors/expected/missing_label.res.expected b/jscomp/build_tests/super_errors/expected/missing_label.res.expected new file mode 100644 index 0000000000..cc693a3312 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/missing_label.res.expected @@ -0,0 +1,10 @@ + + We've found a bug for you! + /.../fixtures/missing_label.res:3:9 + + 1 │ let f = (~a) => a ++ "" + 2 │ + 3 │ let _ = f("") + 4 │ + + Label ~a was omitted in the application of this labeled function. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/missing_labels.res.expected b/jscomp/build_tests/super_errors/expected/missing_labels.res.expected new file mode 100644 index 0000000000..3783b11ef5 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/missing_labels.res.expected @@ -0,0 +1,10 @@ + + We've found a bug for you! + /.../fixtures/missing_labels.res:3:9 + + 1 │ let f = (~a, ~b) => a ++ b + 2 │ + 3 │ let _ = f("", "") + 4 │ + + Labels ~a, ~b were omitted in the application of this labeled function. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/missing_label.res b/jscomp/build_tests/super_errors/fixtures/missing_label.res new file mode 100644 index 0000000000..f67eb4692d --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/missing_label.res @@ -0,0 +1,3 @@ +let f = (~a) => a ++ "" + +let _ = f("") diff --git a/jscomp/build_tests/super_errors/fixtures/missing_labels.res b/jscomp/build_tests/super_errors/fixtures/missing_labels.res new file mode 100644 index 0000000000..9953d572d7 --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/missing_labels.res @@ -0,0 +1,3 @@ +let f = (~a, ~b) => a ++ b + +let _ = f("", "") diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index 77b5a748af..59ded57213 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -4056,9 +4056,13 @@ let report_error env ppf = function | Illegal_letrec_pat -> fprintf ppf "Only variables are allowed as left-hand side of `let rec'" + | Labels_omitted [label] -> + fprintf ppf "Label ~%s was omitted in the application of this labeled function." + label | Labels_omitted labels -> - fprintf ppf "For labeled function, labels %s were omitted in the application of this function." - (String.concat ", " labels) + let labelsString = labels |> List.map(fun label -> "~" ^ label) |> String.concat ", " in + fprintf ppf "Labels %s were omitted in the application of this labeled function." + labelsString | Empty_record_literal -> fprintf ppf "Empty record literal {} should be type annotated or used in a record context." | Uncurried_arity_mismatch (typ, arity, args) ->