Skip to content

Commit 6d81258

Browse files
authored
Merge pull request #5468 from rescript-lang/convert-more-error-messages-from-ml-to-res
convert more warnings in OCaml syntax to ReScript syntax
2 parents 3c5f1a2 + 85d5826 commit 6d81258

File tree

9 files changed

+169
-54
lines changed

9 files changed

+169
-54
lines changed

jscomp/build_tests/super_errors/expected/warnings4.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
14 │
1111

1212
You forgot to handle a possible case here, for example:
13-
(#second(_)|#fourth|#third)
13+
#second(_) | #fourth | #third
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
2+
Warning number 9
3+
/.../fixtures/warnings5.res:12:3-21
4+
5+
10 │
6+
11 │ switch y {
7+
12 │ | {otherValue: false} => Js.log("first")
8+
13 │ }
9+
14 │
10+
11+
the following labels are not bound in this record pattern: someValue, typ
12+
Either bind these labels explicitly or add ', _' to the pattern.
13+
14+
15+
Warning number 8
16+
/.../fixtures/warnings5.res:11:1-13:1
17+
18+
9 │ @val external y: someRecord = "otherVariable"
19+
10 │
20+
11 │ switch y {
21+
12 │ | {otherValue: false} => Js.log("first")
22+
13 │ }
23+
14 │
24+
15 │ switch y {
25+
26+
You forgot to handle a possible case here, for example:
27+
{otherValue: true}
28+
29+
30+
Warning number 9
31+
/.../fixtures/warnings5.res:16:3-26
32+
33+
14 │
34+
15 │ switch y {
35+
16 │ | {typ: WithPayload(true)} => Js.log("first")
36+
17 │ }
37+
18 │
38+
39+
the following labels are not bound in this record pattern: someValue, otherValue
40+
Either bind these labels explicitly or add ', _' to the pattern.
41+
42+
43+
Warning number 8
44+
/.../fixtures/warnings5.res:15:1-17:1
45+
46+
13 │ }
47+
14 │
48+
15 │ switch y {
49+
16 │ | {typ: WithPayload(true)} => Js.log("first")
50+
17 │ }
51+
18 │
52+
19 │ let arr = [1]
53+
54+
You forgot to handle a possible case here, for example:
55+
{typ: WithPayload(false)} |
56+
{typ: Variant | One | Two | Three | Four | Five | Six | Seven(_)}
57+
58+
59+
Warning number 8
60+
/.../fixtures/warnings5.res:21:1-23:1
61+
62+
19 │ let arr = [1]
63+
20 │
64+
21 │ switch arr {
65+
22 │ | [] => Js.log("")
66+
23 │ }
67+
24 │
68+
25 │ switch arr {
69+
70+
You forgot to handle a possible case here, for example:
71+
[_]
72+
73+
74+
Warning number 8
75+
/.../fixtures/warnings5.res:25:1-27:1
76+
77+
23 │ }
78+
24 │
79+
25 │ switch arr {
80+
26 │ | [one] => Js.log(one)
81+
27 │ }
82+
28 │
83+
29 │ switch arr {
84+
85+
You forgot to handle a possible case here, for example:
86+
[]
87+
88+
89+
Warning number 8
90+
/.../fixtures/warnings5.res:29:1-31:1
91+
92+
27 │ }
93+
28 │
94+
29 │ switch arr {
95+
30 │ | [1, 2] => ()
96+
31 │ }
97+
32 │
98+
99+
You forgot to handle a possible case here, for example:
100+
[1, 0] | [0, _] | []
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
type someTyp = Variant | WithPayload(bool) | One | Two | Three | Four | Five | Six | Seven(int)
2+
3+
type someRecord = {
4+
someValue: string,
5+
otherValue: bool,
6+
typ: someTyp,
7+
}
8+
9+
@val external y: someRecord = "otherVariable"
10+
11+
switch y {
12+
| {otherValue: false} => Js.log("first")
13+
}
14+
15+
switch y {
16+
| {typ: WithPayload(true)} => Js.log("first")
17+
}
18+
19+
let arr = [1]
20+
21+
switch arr {
22+
| [] => Js.log("")
23+
}
24+
25+
switch arr {
26+
| [one] => Js.log(one)
27+
}
28+
29+
switch arr {
30+
| [1, 2] => ()
31+
}

jscomp/ext/warnings.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ let message = function
322322
"You forgot to handle a possible case here, for example: \n " ^ s
323323
| Non_closed_record_pattern s ->
324324
"the following labels are not bound in this record pattern: " ^ s
325-
^ "\nEither bind these labels explicitly or add '; _' to the pattern."
325+
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
326326
| Statement_type ->
327327
"This expression returns a value, but you're not doing anything with it. \
328328
If this is on purpose, wrap it with `ignore`."

jscomp/ml/parmatch.ml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ let rec pretty_val ppf v =
406406
| Tpat_construct (_, cstr, []) ->
407407
fprintf ppf "%s" cstr.cstr_name
408408
| Tpat_construct (_, cstr, [w]) ->
409-
fprintf ppf "@[<2>%s@ %a@]" cstr.cstr_name pretty_arg w
409+
fprintf ppf "@[<2>%s(%a)@]" cstr.cstr_name pretty_arg w
410410
| Tpat_construct (_, cstr, vs) ->
411411
let name = cstr.cstr_name in
412412
begin match (name, vs) with
@@ -426,23 +426,19 @@ let rec pretty_val ppf v =
426426
| _ -> true) in
427427
begin match filtered_lvs with
428428
| [] -> fprintf ppf "_"
429-
| (_, lbl, _) :: q ->
430-
let elision_mark ppf =
431-
(* we assume that there is no label repetitions here *)
432-
if Array.length lbl.lbl_all > 1 + List.length q then
433-
fprintf ppf ";@ _@ "
434-
else () in
429+
| (_, _lbl, _) :: _q ->
430+
let elision_mark _ = () in
435431
fprintf ppf "@[{%a%t}@]"
436432
pretty_lvals filtered_lvs elision_mark
437433
end
438434
| Tpat_array vs ->
439-
fprintf ppf "@[[| %a |]@]" (pretty_vals " ;") vs
435+
fprintf ppf "@[[%a]@]" (pretty_vals ",") vs
440436
| Tpat_lazy v ->
441437
fprintf ppf "@[<2>lazy@ %a@]" pretty_arg v
442438
| Tpat_alias (v, x,_) ->
443439
fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.print x
444440
| Tpat_or (v,w,_) ->
445-
fprintf ppf "@[(%a|@,%a)@]" pretty_or v pretty_or w
441+
fprintf ppf "@[%a | @,%a@]" pretty_or v pretty_or w
446442

447443
and pretty_car ppf v = match v.pat_desc with
448444
| Tpat_construct (_,cstr, [_ ; _])
@@ -463,7 +459,7 @@ and pretty_arg ppf v = match v.pat_desc with
463459

464460
and pretty_or ppf v = match v.pat_desc with
465461
| Tpat_or (v,w,_) ->
466-
fprintf ppf "%a|@,%a" pretty_or v pretty_or w
462+
fprintf ppf "%a | @,%a" pretty_or v pretty_or w
467463
| _ -> pretty_val ppf v
468464

469465
and pretty_vals sep ppf = function
@@ -475,9 +471,9 @@ and pretty_vals sep ppf = function
475471
and pretty_lvals ppf = function
476472
| [] -> ()
477473
| [_,lbl,v] ->
478-
fprintf ppf "%s=%a" lbl.lbl_name pretty_val v
474+
fprintf ppf "%s: %a" lbl.lbl_name pretty_val v
479475
| (_, lbl,v)::rest ->
480-
fprintf ppf "%s=%a;@ %a"
476+
fprintf ppf "%s: %a,@ %a"
481477
lbl.lbl_name pretty_val v pretty_lvals rest
482478

483479
let top_pretty ppf v =

lib/4.06.1/unstable/all_ounit_tests.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9870,7 +9870,7 @@ let message = function
98709870
"You forgot to handle a possible case here, for example: \n " ^ s
98719871
| Non_closed_record_pattern s ->
98729872
"the following labels are not bound in this record pattern: " ^ s
9873-
^ "\nEither bind these labels explicitly or add '; _' to the pattern."
9873+
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
98749874
| Statement_type ->
98759875
"This expression returns a value, but you're not doing anything with it. \
98769876
If this is on purpose, wrap it with `ignore`."

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,7 +2275,7 @@ let message = function
22752275
"You forgot to handle a possible case here, for example: \n " ^ s
22762276
| Non_closed_record_pattern s ->
22772277
"the following labels are not bound in this record pattern: " ^ s
2278-
^ "\nEither bind these labels explicitly or add '; _' to the pattern."
2278+
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
22792279
| Statement_type ->
22802280
"This expression returns a value, but you're not doing anything with it. \
22812281
If this is on purpose, wrap it with `ignore`."
@@ -26812,7 +26812,7 @@ let rec pretty_val ppf v =
2681226812
| Tpat_construct (_, cstr, []) ->
2681326813
fprintf ppf "%s" cstr.cstr_name
2681426814
| Tpat_construct (_, cstr, [w]) ->
26815-
fprintf ppf "@[<2>%s@ %a@]" cstr.cstr_name pretty_arg w
26815+
fprintf ppf "@[<2>%s(%a)@]" cstr.cstr_name pretty_arg w
2681626816
| Tpat_construct (_, cstr, vs) ->
2681726817
let name = cstr.cstr_name in
2681826818
begin match (name, vs) with
@@ -26832,23 +26832,19 @@ let rec pretty_val ppf v =
2683226832
| _ -> true) in
2683326833
begin match filtered_lvs with
2683426834
| [] -> fprintf ppf "_"
26835-
| (_, lbl, _) :: q ->
26836-
let elision_mark ppf =
26837-
(* we assume that there is no label repetitions here *)
26838-
if Array.length lbl.lbl_all > 1 + List.length q then
26839-
fprintf ppf ";@ _@ "
26840-
else () in
26835+
| (_, _lbl, _) :: _q ->
26836+
let elision_mark _ = () in
2684126837
fprintf ppf "@[{%a%t}@]"
2684226838
pretty_lvals filtered_lvs elision_mark
2684326839
end
2684426840
| Tpat_array vs ->
26845-
fprintf ppf "@[[| %a |]@]" (pretty_vals " ;") vs
26841+
fprintf ppf "@[[%a]@]" (pretty_vals ",") vs
2684626842
| Tpat_lazy v ->
2684726843
fprintf ppf "@[<2>lazy@ %a@]" pretty_arg v
2684826844
| Tpat_alias (v, x,_) ->
2684926845
fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.print x
2685026846
| Tpat_or (v,w,_) ->
26851-
fprintf ppf "@[(%a|@,%a)@]" pretty_or v pretty_or w
26847+
fprintf ppf "@[%a | @,%a@]" pretty_or v pretty_or w
2685226848

2685326849
and pretty_car ppf v = match v.pat_desc with
2685426850
| Tpat_construct (_,cstr, [_ ; _])
@@ -26869,7 +26865,7 @@ and pretty_arg ppf v = match v.pat_desc with
2686926865

2687026866
and pretty_or ppf v = match v.pat_desc with
2687126867
| Tpat_or (v,w,_) ->
26872-
fprintf ppf "%a|@,%a" pretty_or v pretty_or w
26868+
fprintf ppf "%a | @,%a" pretty_or v pretty_or w
2687326869
| _ -> pretty_val ppf v
2687426870

2687526871
and pretty_vals sep ppf = function
@@ -26881,9 +26877,9 @@ and pretty_vals sep ppf = function
2688126877
and pretty_lvals ppf = function
2688226878
| [] -> ()
2688326879
| [_,lbl,v] ->
26884-
fprintf ppf "%s=%a" lbl.lbl_name pretty_val v
26880+
fprintf ppf "%s: %a" lbl.lbl_name pretty_val v
2688526881
| (_, lbl,v)::rest ->
26886-
fprintf ppf "%s=%a;@ %a"
26882+
fprintf ppf "%s: %a,@ %a"
2688726883
lbl.lbl_name pretty_val v pretty_lvals rest
2688826884

2688926885
let top_pretty ppf v =

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ let message = function
20222022
"You forgot to handle a possible case here, for example: \n " ^ s
20232023
| Non_closed_record_pattern s ->
20242024
"the following labels are not bound in this record pattern: " ^ s
2025-
^ "\nEither bind these labels explicitly or add '; _' to the pattern."
2025+
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
20262026
| Statement_type ->
20272027
"This expression returns a value, but you're not doing anything with it. \
20282028
If this is on purpose, wrap it with `ignore`."
@@ -26812,7 +26812,7 @@ let rec pretty_val ppf v =
2681226812
| Tpat_construct (_, cstr, []) ->
2681326813
fprintf ppf "%s" cstr.cstr_name
2681426814
| Tpat_construct (_, cstr, [w]) ->
26815-
fprintf ppf "@[<2>%s@ %a@]" cstr.cstr_name pretty_arg w
26815+
fprintf ppf "@[<2>%s(%a)@]" cstr.cstr_name pretty_arg w
2681626816
| Tpat_construct (_, cstr, vs) ->
2681726817
let name = cstr.cstr_name in
2681826818
begin match (name, vs) with
@@ -26832,23 +26832,19 @@ let rec pretty_val ppf v =
2683226832
| _ -> true) in
2683326833
begin match filtered_lvs with
2683426834
| [] -> fprintf ppf "_"
26835-
| (_, lbl, _) :: q ->
26836-
let elision_mark ppf =
26837-
(* we assume that there is no label repetitions here *)
26838-
if Array.length lbl.lbl_all > 1 + List.length q then
26839-
fprintf ppf ";@ _@ "
26840-
else () in
26835+
| (_, _lbl, _) :: _q ->
26836+
let elision_mark _ = () in
2684126837
fprintf ppf "@[{%a%t}@]"
2684226838
pretty_lvals filtered_lvs elision_mark
2684326839
end
2684426840
| Tpat_array vs ->
26845-
fprintf ppf "@[[| %a |]@]" (pretty_vals " ;") vs
26841+
fprintf ppf "@[[%a]@]" (pretty_vals ",") vs
2684626842
| Tpat_lazy v ->
2684726843
fprintf ppf "@[<2>lazy@ %a@]" pretty_arg v
2684826844
| Tpat_alias (v, x,_) ->
2684926845
fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.print x
2685026846
| Tpat_or (v,w,_) ->
26851-
fprintf ppf "@[(%a|@,%a)@]" pretty_or v pretty_or w
26847+
fprintf ppf "@[%a | @,%a@]" pretty_or v pretty_or w
2685226848

2685326849
and pretty_car ppf v = match v.pat_desc with
2685426850
| Tpat_construct (_,cstr, [_ ; _])
@@ -26869,7 +26865,7 @@ and pretty_arg ppf v = match v.pat_desc with
2686926865

2687026866
and pretty_or ppf v = match v.pat_desc with
2687126867
| Tpat_or (v,w,_) ->
26872-
fprintf ppf "%a|@,%a" pretty_or v pretty_or w
26868+
fprintf ppf "%a | @,%a" pretty_or v pretty_or w
2687326869
| _ -> pretty_val ppf v
2687426870

2687526871
and pretty_vals sep ppf = function
@@ -26881,9 +26877,9 @@ and pretty_vals sep ppf = function
2688126877
and pretty_lvals ppf = function
2688226878
| [] -> ()
2688326879
| [_,lbl,v] ->
26884-
fprintf ppf "%s=%a" lbl.lbl_name pretty_val v
26880+
fprintf ppf "%s: %a" lbl.lbl_name pretty_val v
2688526881
| (_, lbl,v)::rest ->
26886-
fprintf ppf "%s=%a;@ %a"
26882+
fprintf ppf "%s: %a,@ %a"
2688726883
lbl.lbl_name pretty_val v pretty_lvals rest
2688826884

2688926885
let top_pretty ppf v =

0 commit comments

Comments
 (0)