Skip to content

convert more warnings in OCaml syntax to ReScript syntax #5468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
14 │

You forgot to handle a possible case here, for example:
(#second(_)|#fourth|#third)
#second(_) | #fourth | #third
100 changes: 100 additions & 0 deletions jscomp/build_tests/super_errors/expected/warnings5.res.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

Warning number 9
/.../fixtures/warnings5.res:12:3-21

10 │
11 │ switch y {
12 │ | {otherValue: false} => Js.log("first")
13 │ }
14 │

the following labels are not bound in this record pattern: someValue, typ
Either bind these labels explicitly or add ', _' to the pattern.


Warning number 8
/.../fixtures/warnings5.res:11:1-13:1

9 │ @val external y: someRecord = "otherVariable"
10 │
11 │ switch y {
12 │ | {otherValue: false} => Js.log("first")
13 │ }
14 │
15 │ switch y {

You forgot to handle a possible case here, for example:
{otherValue: true}


Warning number 9
/.../fixtures/warnings5.res:16:3-26

14 │
15 │ switch y {
16 │ | {typ: WithPayload(true)} => Js.log("first")
17 │ }
18 │

the following labels are not bound in this record pattern: someValue, otherValue
Either bind these labels explicitly or add ', _' to the pattern.


Warning number 8
/.../fixtures/warnings5.res:15:1-17:1

13 │ }
14 │
15 │ switch y {
16 │ | {typ: WithPayload(true)} => Js.log("first")
17 │ }
18 │
19 │ let arr = [1]

You forgot to handle a possible case here, for example:
{typ: WithPayload(false)} |
{typ: Variant | One | Two | Three | Four | Five | Six | Seven(_)}


Warning number 8
/.../fixtures/warnings5.res:21:1-23:1

19 │ let arr = [1]
20 │
21 │ switch arr {
22 │ | [] => Js.log("")
23 │ }
24 │
25 │ switch arr {

You forgot to handle a possible case here, for example:
[_]


Warning number 8
/.../fixtures/warnings5.res:25:1-27:1

23 │ }
24 │
25 │ switch arr {
26 │ | [one] => Js.log(one)
27 │ }
28 │
29 │ switch arr {

You forgot to handle a possible case here, for example:
[]


Warning number 8
/.../fixtures/warnings5.res:29:1-31:1

27 │ }
28 │
29 │ switch arr {
30 │ | [1, 2] => ()
31 │ }
32 │

You forgot to handle a possible case here, for example:
[1, 0] | [0, _] | []
31 changes: 31 additions & 0 deletions jscomp/build_tests/super_errors/fixtures/warnings5.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
type someTyp = Variant | WithPayload(bool) | One | Two | Three | Four | Five | Six | Seven(int)

type someRecord = {
someValue: string,
otherValue: bool,
typ: someTyp,
}

@val external y: someRecord = "otherVariable"

switch y {
| {otherValue: false} => Js.log("first")
}

switch y {
| {typ: WithPayload(true)} => Js.log("first")
}

let arr = [1]

switch arr {
| [] => Js.log("")
}

switch arr {
| [one] => Js.log(one)
}

switch arr {
| [1, 2] => ()
}
2 changes: 1 addition & 1 deletion jscomp/ext/warnings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ let message = function
"You forgot to handle a possible case here, for example: \n " ^ s
| Non_closed_record_pattern s ->
"the following labels are not bound in this record pattern: " ^ s
^ "\nEither bind these labels explicitly or add '; _' to the pattern."
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
| Statement_type ->
"This expression returns a value, but you're not doing anything with it. \
If this is on purpose, wrap it with `ignore`."
Expand Down
20 changes: 8 additions & 12 deletions jscomp/ml/parmatch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ let rec pretty_val ppf v =
| Tpat_construct (_, cstr, []) ->
fprintf ppf "%s" cstr.cstr_name
| Tpat_construct (_, cstr, [w]) ->
fprintf ppf "@[<2>%s@ %a@]" cstr.cstr_name pretty_arg w
fprintf ppf "@[<2>%s(%a)@]" cstr.cstr_name pretty_arg w
| Tpat_construct (_, cstr, vs) ->
let name = cstr.cstr_name in
begin match (name, vs) with
Expand All @@ -426,23 +426,19 @@ let rec pretty_val ppf v =
| _ -> true) in
begin match filtered_lvs with
| [] -> fprintf ppf "_"
| (_, lbl, _) :: q ->
let elision_mark ppf =
(* we assume that there is no label repetitions here *)
if Array.length lbl.lbl_all > 1 + List.length q then
fprintf ppf ";@ _@ "
else () in
| (_, _lbl, _) :: _q ->
let elision_mark _ = () in
fprintf ppf "@[{%a%t}@]"
pretty_lvals filtered_lvs elision_mark
end
| Tpat_array vs ->
fprintf ppf "@[[| %a |]@]" (pretty_vals " ;") vs
fprintf ppf "@[[%a]@]" (pretty_vals ",") vs
| Tpat_lazy v ->
fprintf ppf "@[<2>lazy@ %a@]" pretty_arg v
| Tpat_alias (v, x,_) ->
fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.print x
| Tpat_or (v,w,_) ->
fprintf ppf "@[(%a|@,%a)@]" pretty_or v pretty_or w
fprintf ppf "@[%a | @,%a@]" pretty_or v pretty_or w

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

and pretty_or ppf v = match v.pat_desc with
| Tpat_or (v,w,_) ->
fprintf ppf "%a|@,%a" pretty_or v pretty_or w
fprintf ppf "%a | @,%a" pretty_or v pretty_or w
| _ -> pretty_val ppf v

and pretty_vals sep ppf = function
Expand All @@ -475,9 +471,9 @@ and pretty_vals sep ppf = function
and pretty_lvals ppf = function
| [] -> ()
| [_,lbl,v] ->
fprintf ppf "%s=%a" lbl.lbl_name pretty_val v
fprintf ppf "%s: %a" lbl.lbl_name pretty_val v
| (_, lbl,v)::rest ->
fprintf ppf "%s=%a;@ %a"
fprintf ppf "%s: %a,@ %a"
lbl.lbl_name pretty_val v pretty_lvals rest

let top_pretty ppf v =
Expand Down
2 changes: 1 addition & 1 deletion lib/4.06.1/unstable/all_ounit_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9870,7 +9870,7 @@ let message = function
"You forgot to handle a possible case here, for example: \n " ^ s
| Non_closed_record_pattern s ->
"the following labels are not bound in this record pattern: " ^ s
^ "\nEither bind these labels explicitly or add '; _' to the pattern."
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
| Statement_type ->
"This expression returns a value, but you're not doing anything with it. \
If this is on purpose, wrap it with `ignore`."
Expand Down
22 changes: 9 additions & 13 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@ let message = function
"You forgot to handle a possible case here, for example: \n " ^ s
| Non_closed_record_pattern s ->
"the following labels are not bound in this record pattern: " ^ s
^ "\nEither bind these labels explicitly or add '; _' to the pattern."
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
| Statement_type ->
"This expression returns a value, but you're not doing anything with it. \
If this is on purpose, wrap it with `ignore`."
Expand Down Expand Up @@ -26812,7 +26812,7 @@ let rec pretty_val ppf v =
| Tpat_construct (_, cstr, []) ->
fprintf ppf "%s" cstr.cstr_name
| Tpat_construct (_, cstr, [w]) ->
fprintf ppf "@[<2>%s@ %a@]" cstr.cstr_name pretty_arg w
fprintf ppf "@[<2>%s(%a)@]" cstr.cstr_name pretty_arg w
| Tpat_construct (_, cstr, vs) ->
let name = cstr.cstr_name in
begin match (name, vs) with
Expand All @@ -26832,23 +26832,19 @@ let rec pretty_val ppf v =
| _ -> true) in
begin match filtered_lvs with
| [] -> fprintf ppf "_"
| (_, lbl, _) :: q ->
let elision_mark ppf =
(* we assume that there is no label repetitions here *)
if Array.length lbl.lbl_all > 1 + List.length q then
fprintf ppf ";@ _@ "
else () in
| (_, _lbl, _) :: _q ->
let elision_mark _ = () in
fprintf ppf "@[{%a%t}@]"
pretty_lvals filtered_lvs elision_mark
end
| Tpat_array vs ->
fprintf ppf "@[[| %a |]@]" (pretty_vals " ;") vs
fprintf ppf "@[[%a]@]" (pretty_vals ",") vs
| Tpat_lazy v ->
fprintf ppf "@[<2>lazy@ %a@]" pretty_arg v
| Tpat_alias (v, x,_) ->
fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.print x
| Tpat_or (v,w,_) ->
fprintf ppf "@[(%a|@,%a)@]" pretty_or v pretty_or w
fprintf ppf "@[%a | @,%a@]" pretty_or v pretty_or w

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

and pretty_or ppf v = match v.pat_desc with
| Tpat_or (v,w,_) ->
fprintf ppf "%a|@,%a" pretty_or v pretty_or w
fprintf ppf "%a | @,%a" pretty_or v pretty_or w
| _ -> pretty_val ppf v

and pretty_vals sep ppf = function
Expand All @@ -26881,9 +26877,9 @@ and pretty_vals sep ppf = function
and pretty_lvals ppf = function
| [] -> ()
| [_,lbl,v] ->
fprintf ppf "%s=%a" lbl.lbl_name pretty_val v
fprintf ppf "%s: %a" lbl.lbl_name pretty_val v
| (_, lbl,v)::rest ->
fprintf ppf "%s=%a;@ %a"
fprintf ppf "%s: %a,@ %a"
lbl.lbl_name pretty_val v pretty_lvals rest

let top_pretty ppf v =
Expand Down
22 changes: 9 additions & 13 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ let message = function
"You forgot to handle a possible case here, for example: \n " ^ s
| Non_closed_record_pattern s ->
"the following labels are not bound in this record pattern: " ^ s
^ "\nEither bind these labels explicitly or add '; _' to the pattern."
^ "\nEither bind these labels explicitly or add ', _' to the pattern."
| Statement_type ->
"This expression returns a value, but you're not doing anything with it. \
If this is on purpose, wrap it with `ignore`."
Expand Down Expand Up @@ -26812,7 +26812,7 @@ let rec pretty_val ppf v =
| Tpat_construct (_, cstr, []) ->
fprintf ppf "%s" cstr.cstr_name
| Tpat_construct (_, cstr, [w]) ->
fprintf ppf "@[<2>%s@ %a@]" cstr.cstr_name pretty_arg w
fprintf ppf "@[<2>%s(%a)@]" cstr.cstr_name pretty_arg w
| Tpat_construct (_, cstr, vs) ->
let name = cstr.cstr_name in
begin match (name, vs) with
Expand All @@ -26832,23 +26832,19 @@ let rec pretty_val ppf v =
| _ -> true) in
begin match filtered_lvs with
| [] -> fprintf ppf "_"
| (_, lbl, _) :: q ->
let elision_mark ppf =
(* we assume that there is no label repetitions here *)
if Array.length lbl.lbl_all > 1 + List.length q then
fprintf ppf ";@ _@ "
else () in
| (_, _lbl, _) :: _q ->
let elision_mark _ = () in
fprintf ppf "@[{%a%t}@]"
pretty_lvals filtered_lvs elision_mark
end
| Tpat_array vs ->
fprintf ppf "@[[| %a |]@]" (pretty_vals " ;") vs
fprintf ppf "@[[%a]@]" (pretty_vals ",") vs
| Tpat_lazy v ->
fprintf ppf "@[<2>lazy@ %a@]" pretty_arg v
| Tpat_alias (v, x,_) ->
fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.print x
| Tpat_or (v,w,_) ->
fprintf ppf "@[(%a|@,%a)@]" pretty_or v pretty_or w
fprintf ppf "@[%a | @,%a@]" pretty_or v pretty_or w

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

and pretty_or ppf v = match v.pat_desc with
| Tpat_or (v,w,_) ->
fprintf ppf "%a|@,%a" pretty_or v pretty_or w
fprintf ppf "%a | @,%a" pretty_or v pretty_or w
| _ -> pretty_val ppf v

and pretty_vals sep ppf = function
Expand All @@ -26881,9 +26877,9 @@ and pretty_vals sep ppf = function
and pretty_lvals ppf = function
| [] -> ()
| [_,lbl,v] ->
fprintf ppf "%s=%a" lbl.lbl_name pretty_val v
fprintf ppf "%s: %a" lbl.lbl_name pretty_val v
| (_, lbl,v)::rest ->
fprintf ppf "%s=%a;@ %a"
fprintf ppf "%s: %a,@ %a"
lbl.lbl_name pretty_val v pretty_lvals rest

let top_pretty ppf v =
Expand Down
Loading