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 2 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
84 changes: 84 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,84 @@

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})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a little dense.
Aslo, parens probl non needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cristianoc check the latest commit, what do you think?



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 │

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

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)
}
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
16 changes: 6 additions & 10 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,17 +426,13 @@ 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,_) ->
Expand Down Expand Up @@ -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
18 changes: 7 additions & 11 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,17 +26832,13 @@ 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,_) ->
Expand Down Expand Up @@ -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
18 changes: 7 additions & 11 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,17 +26832,13 @@ 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,_) ->
Expand Down Expand Up @@ -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
18 changes: 7 additions & 11 deletions lib/4.06.1/whole_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 @@ -186753,7 +186753,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 @@ -186773,17 +186773,13 @@ 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,_) ->
Expand Down Expand Up @@ -186822,9 +186818,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