diff --git a/jscomp/build_tests/super_errors/expected/warnings4.res.expected b/jscomp/build_tests/super_errors/expected/warnings4.res.expected index 125df3768f..dfa23450b8 100644 --- a/jscomp/build_tests/super_errors/expected/warnings4.res.expected +++ b/jscomp/build_tests/super_errors/expected/warnings4.res.expected @@ -10,4 +10,4 @@ 14 │ You forgot to handle a possible case here, for example: - (#second(_)|#fourth|#third) \ No newline at end of file + #second(_) | #fourth | #third \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/warnings5.res.expected b/jscomp/build_tests/super_errors/expected/warnings5.res.expected new file mode 100644 index 0000000000..ecb9b72d35 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/warnings5.res.expected @@ -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, _] | [] \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/warnings5.res b/jscomp/build_tests/super_errors/fixtures/warnings5.res new file mode 100644 index 0000000000..dc09c587f1 --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/warnings5.res @@ -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] => () +} diff --git a/jscomp/ext/warnings.ml b/jscomp/ext/warnings.ml index 8e7aa96384..533cb3bb22 100644 --- a/jscomp/ext/warnings.ml +++ b/jscomp/ext/warnings.ml @@ -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`." diff --git a/jscomp/ml/parmatch.ml b/jscomp/ml/parmatch.ml index 115784e6d5..15b710d0aa 100644 --- a/jscomp/ml/parmatch.ml +++ b/jscomp/ml/parmatch.ml @@ -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 @@ -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, [_ ; _]) @@ -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 @@ -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 = diff --git a/lib/4.06.1/unstable/all_ounit_tests.ml b/lib/4.06.1/unstable/all_ounit_tests.ml index 3c416b3c58..2fa9def60f 100644 --- a/lib/4.06.1/unstable/all_ounit_tests.ml +++ b/lib/4.06.1/unstable/all_ounit_tests.ml @@ -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`." diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index c0339fe13d..a44c8eeb25 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -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`." @@ -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 @@ -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, [_ ; _]) @@ -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 @@ -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 = diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index 6629c9815c..0c243b7a3a 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -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`." @@ -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 @@ -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, [_ ; _]) @@ -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 @@ -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 = diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index e9c76f3d4f..736cfb7029 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -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`." @@ -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 @@ -186773,23 +186773,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, [_ ; _]) @@ -186810,7 +186806,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 @@ -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 =