Skip to content

Commit 3151d66

Browse files
authored
Improve error message for missing label(s) in function application (#6576)
1 parent d69d438 commit 3151d66

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
- 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
1919
- Fix issue with recursive modules and uncurried. https://github.com/rescript-lang/rescript-compiler/pull/6575
2020

21+
#### :nail_care: Polish
22+
23+
- Improve error message for missing label(s) in function application. https://github.com/rescript-lang/rescript-compiler/pull/6576
24+
2125
# 11.0.0
2226

2327
No changes compared to rc.9.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/missing_label.res:3:9
4+
5+
1 │ let f = (~a) => a ++ ""
6+
2 │
7+
3 │ let _ = f("")
8+
4 │
9+
10+
Label ~a was omitted in the application of this labeled function.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/missing_labels.res:3:9
4+
5+
1 │ let f = (~a, ~b) => a ++ b
6+
2 │
7+
3 │ let _ = f("", "")
8+
4 │
9+
10+
Labels ~a, ~b were omitted in the application of this labeled function.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let f = (~a) => a ++ ""
2+
3+
let _ = f("")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let f = (~a, ~b) => a ++ b
2+
3+
let _ = f("", "")

jscomp/ml/typecore.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,9 +4056,13 @@ let report_error env ppf = function
40564056
| Illegal_letrec_pat ->
40574057
fprintf ppf
40584058
"Only variables are allowed as left-hand side of `let rec'"
4059+
| Labels_omitted [label] ->
4060+
fprintf ppf "Label ~%s was omitted in the application of this labeled function."
4061+
label
40594062
| Labels_omitted labels ->
4060-
fprintf ppf "For labeled function, labels %s were omitted in the application of this function."
4061-
(String.concat ", " labels)
4063+
let labelsString = labels |> List.map(fun label -> "~" ^ label) |> String.concat ", " in
4064+
fprintf ppf "Labels %s were omitted in the application of this labeled function."
4065+
labelsString
40624066
| Empty_record_literal ->
40634067
fprintf ppf "Empty record literal {} should be type annotated or used in a record context."
40644068
| Uncurried_arity_mismatch (typ, arity, args) ->

0 commit comments

Comments
 (0)