From 7a04c030af49dfaff712020ea8d86719b314bfc5 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 18 Jan 2024 17:51:34 +0700 Subject: [PATCH 1/3] Improve error message for missing label(s) in function application --- jscomp/ml/typecore.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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) -> From c6802ba32ea5a3c5f184b5f42f9f4ada904fe913 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 18 Jan 2024 19:34:24 +0700 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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. From 8c27920f84aafd69c369c0c4c0af7157e0312c73 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sat, 20 Jan 2024 14:05:55 +0700 Subject: [PATCH 3/3] Add test for missing labels error --- .../super_errors/expected/missing_label.res.expected | 10 ++++++++++ .../super_errors/expected/missing_labels.res.expected | 10 ++++++++++ .../super_errors/fixtures/missing_label.res | 3 +++ .../super_errors/fixtures/missing_labels.res | 3 +++ 4 files changed, 26 insertions(+) create mode 100644 jscomp/build_tests/super_errors/expected/missing_label.res.expected create mode 100644 jscomp/build_tests/super_errors/expected/missing_labels.res.expected create mode 100644 jscomp/build_tests/super_errors/fixtures/missing_label.res create mode 100644 jscomp/build_tests/super_errors/fixtures/missing_labels.res 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("", "")