Skip to content

Commit b5e045d

Browse files
committed
bring back configured as error for super_errors
1 parent 129d428 commit b5e045d

File tree

8 files changed

+66
-54
lines changed

8 files changed

+66
-54
lines changed

jscomp/build_tests/super_errors/expected/highlighting4.re.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
Warning number 3
2+
Warning number 3 (configured as error)
33
/.../fixtures/highlighting4.re:5:10
44

55
3 │ [@deprecated]

jscomp/build_tests/super_errors/fixtures/highlighting4.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
[@warnerror "A"];
22
/* single char highlighted */
33
[@deprecated]
44
type a = int;

jscomp/super_errors/super_location.ml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ let print_loc ~normalizedRange ppf (loc : Location.t) =
2525
fprintf ppf "@{<filename>%a@}%a" print_filename loc.loc_start.pos_fname dim_loc normalizedRange
2626
;;
2727

28-
let print intro ppf (loc : Location.t) =
29-
fprintf ppf "@[@{<error>%s@}@]@," intro;
28+
let print ~message_kind intro ppf (loc : Location.t) =
29+
begin match message_kind with
30+
| `warning -> fprintf ppf "@[@{<info>%s@}@]@," intro
31+
| `warning_as_error -> fprintf ppf "@[@{<error>%s@} (configured as error) @]@," intro
32+
| `error -> fprintf ppf "@[@{<error>%s@}@]@," intro
33+
end;
3034
(* ocaml's reported line/col numbering is horrible and super error-prone
3135
when being handled programmatically (or humanly for that matter. If you're
3236
an ocaml contributor reading this: who the heck reads the character count
@@ -60,7 +64,7 @@ let print intro ppf (loc : Location.t) =
6064
branch might not be reached (aka no inline file content display) so
6165
we don't wanna end up with two line breaks in the the consequent *)
6266
fprintf ppf "@,%a"
63-
(Super_misc.print_file ~lines ~range)
67+
(Super_misc.print_file ~is_warning:(message_kind=`warning) ~lines ~range)
6468
()
6569
with
6670
(* this might happen if the file is e.g. "", "_none_" or any of the fake file name placeholders.
@@ -74,7 +78,7 @@ let print intro ppf (loc : Location.t) =
7478
let rec super_error_reporter ppf ({loc; msg; sub} : Location.error) =
7579
setup_colors ();
7680
(* open a vertical box. Everything in our message is indented 2 spaces *)
77-
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print "We've found a bug for you!") loc msg;
81+
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print ~message_kind:`error "We've found a bug for you!") loc msg;
7882
List.iter (Format.fprintf ppf "@,@[%a@]" super_error_reporter) sub
7983
(* no need to flush here; location's report_exception (which uses this ultimately) flushes *)
8084

@@ -84,10 +88,11 @@ let rec super_error_reporter ppf ({loc; msg; sub} : Location.error) =
8488
let super_warning_printer loc ppf w =
8589
match Warnings.report w with
8690
| `Inactive -> ()
87-
| `Active { Warnings. number = _; message = _; sub_locs = _} ->
91+
| `Active { Warnings. number = _; message = _; is_error; sub_locs = _} ->
8892
setup_colors ();
89-
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]@."
90-
(print ("Warning number " ^ (Warnings.number w |> string_of_int)))
93+
let message_kind = if is_error then `warning_as_error else `warning in
94+
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]"
95+
(print ~message_kind ("Warning number " ^ (Warnings.number w |> string_of_int)))
9196
loc
9297
(Warnings.message w);
9398
(* at this point, you can display sub_locs too, from e.g. https://github.com/ocaml/ocaml/commit/f6d53cc38f87c67fbf49109f5fb79a0334bab17a

jscomp/super_errors/super_misc.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type current_printed_line_status =
3636
(* Range coordinates all 1-indexed, like for editors. Otherwise this code
3737
would have way too many off-by-one errors *)
3838
let print_file
39-
39+
~is_warning
4040
(* start_line_start_char inclusive, end_line_end_char exclusive *)
4141
~range:((start_line, start_line_start_char), (end_line, end_line_end_char))
4242
~lines
@@ -69,10 +69,10 @@ ppf
6969
| Some n -> n
7070
in
7171
(* coloring *)
72-
let highlighted_line_number : _ format = "@{<error>%s@}%a" in
72+
let highlighted_line_number : _ format = if is_warning then "@{<info>%s@}%a" else "@{<error>%s@}%a" in
7373

7474
let print_char_maybe_highlight ~begin_highlight_line ~end_highlight_line ch =
75-
let highlighted_open_tag: _ format = "@{<error>" in
75+
let highlighted_open_tag: _ format = if is_warning then "@{<info>" else "@{<error>" in
7676
if begin_highlight_line then fprintf ppf highlighted_open_tag;
7777
fprintf ppf "%c@," ch;
7878
if end_highlight_line then fprintf ppf "@}"

jscomp/super_errors/super_misc.mli

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
(** Range coordinates all 1-indexed, like for editors. Otherwise this code
22
would have way too many off-by-one errors *)
3-
val print_file:
4-
range:(int * int) * (int * int) ->
5-
lines:string array -> Format.formatter -> unit -> unit
3+
val print_file: is_warning:bool -> range:(int * int) * (int * int) -> lines:string array -> Format.formatter -> unit -> unit

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -409500,9 +409500,7 @@ module Super_misc : sig
409500409500
#1 "super_misc.mli"
409501409501
(** Range coordinates all 1-indexed, like for editors. Otherwise this code
409502409502
would have way too many off-by-one errors *)
409503-
val print_file:
409504-
range:(int * int) * (int * int) ->
409505-
lines:string array -> Format.formatter -> unit -> unit
409503+
val print_file: is_warning:bool -> range:(int * int) * (int * int) -> lines:string array -> Format.formatter -> unit -> unit
409506409504

409507409505
end = struct
409508409506
#1 "super_misc.ml"
@@ -409544,7 +409542,7 @@ type current_printed_line_status =
409544409542
(* Range coordinates all 1-indexed, like for editors. Otherwise this code
409545409543
would have way too many off-by-one errors *)
409546409544
let print_file
409547-
409545+
~is_warning
409548409546
(* start_line_start_char inclusive, end_line_end_char exclusive *)
409549409547
~range:((start_line, start_line_start_char), (end_line, end_line_end_char))
409550409548
~lines
@@ -409577,10 +409575,10 @@ ppf
409577409575
| Some n -> n
409578409576
in
409579409577
(* coloring *)
409580-
let highlighted_line_number : _ format = "@{<error>%s@}%a" in
409578+
let highlighted_line_number : _ format = if is_warning then "@{<info>%s@}%a" else "@{<error>%s@}%a" in
409581409579

409582409580
let print_char_maybe_highlight ~begin_highlight_line ~end_highlight_line ch =
409583-
let highlighted_open_tag: _ format = "@{<error>" in
409581+
let highlighted_open_tag: _ format = if is_warning then "@{<info>" else "@{<error>" in
409584409582
if begin_highlight_line then fprintf ppf highlighted_open_tag;
409585409583
fprintf ppf "%c@," ch;
409586409584
if end_highlight_line then fprintf ppf "@}"
@@ -409721,8 +409719,12 @@ let print_loc ~normalizedRange ppf (loc : Location.t) =
409721409719
fprintf ppf "@{<filename>%a@}%a" print_filename loc.loc_start.pos_fname dim_loc normalizedRange
409722409720
;;
409723409721

409724-
let print intro ppf (loc : Location.t) =
409725-
fprintf ppf "@[@{<error>%s@}@]@," intro;
409722+
let print ~message_kind intro ppf (loc : Location.t) =
409723+
begin match message_kind with
409724+
| `warning -> fprintf ppf "@[@{<info>%s@}@]@," intro
409725+
| `warning_as_error -> fprintf ppf "@[@{<error>%s@} (configured as error) @]@," intro
409726+
| `error -> fprintf ppf "@[@{<error>%s@}@]@," intro
409727+
end;
409726409728
(* ocaml's reported line/col numbering is horrible and super error-prone
409727409729
when being handled programmatically (or humanly for that matter. If you're
409728409730
an ocaml contributor reading this: who the heck reads the character count
@@ -409756,7 +409758,7 @@ let print intro ppf (loc : Location.t) =
409756409758
branch might not be reached (aka no inline file content display) so
409757409759
we don't wanna end up with two line breaks in the the consequent *)
409758409760
fprintf ppf "@,%a"
409759-
(Super_misc.print_file ~lines ~range)
409761+
(Super_misc.print_file ~is_warning:(message_kind=`warning) ~lines ~range)
409760409762
()
409761409763
with
409762409764
(* this might happen if the file is e.g. "", "_none_" or any of the fake file name placeholders.
@@ -409770,7 +409772,7 @@ let print intro ppf (loc : Location.t) =
409770409772
let rec super_error_reporter ppf ({loc; msg; sub} : Location.error) =
409771409773
setup_colors ();
409772409774
(* open a vertical box. Everything in our message is indented 2 spaces *)
409773-
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print "We've found a bug for you!") loc msg;
409775+
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print ~message_kind:`error "We've found a bug for you!") loc msg;
409774409776
List.iter (Format.fprintf ppf "@,@[%a@]" super_error_reporter) sub
409775409777
(* no need to flush here; location's report_exception (which uses this ultimately) flushes *)
409776409778

@@ -409780,10 +409782,11 @@ let rec super_error_reporter ppf ({loc; msg; sub} : Location.error) =
409780409782
let super_warning_printer loc ppf w =
409781409783
match Warnings.report w with
409782409784
| `Inactive -> ()
409783-
| `Active { Warnings. number = _; message = _; sub_locs = _} ->
409785+
| `Active { Warnings. number = _; message = _; is_error; sub_locs = _} ->
409784409786
setup_colors ();
409785-
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]@."
409786-
(print ("Warning number " ^ (Warnings.number w |> string_of_int)))
409787+
let message_kind = if is_error then `warning_as_error else `warning in
409788+
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]"
409789+
(print ~message_kind ("Warning number " ^ (Warnings.number w |> string_of_int)))
409787409790
loc
409788409791
(Warnings.message w);
409789409792
(* at this point, you can display sub_locs too, from e.g. https://github.com/ocaml/ocaml/commit/f6d53cc38f87c67fbf49109f5fb79a0334bab17a

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569596,9 +569596,7 @@ module Super_misc : sig
569596569596
#1 "super_misc.mli"
569597569597
(** Range coordinates all 1-indexed, like for editors. Otherwise this code
569598569598
would have way too many off-by-one errors *)
569599-
val print_file:
569600-
range:(int * int) * (int * int) ->
569601-
lines:string array -> Format.formatter -> unit -> unit
569599+
val print_file: is_warning:bool -> range:(int * int) * (int * int) -> lines:string array -> Format.formatter -> unit -> unit
569602569600

569603569601
end = struct
569604569602
#1 "super_misc.ml"
@@ -569640,7 +569638,7 @@ type current_printed_line_status =
569640569638
(* Range coordinates all 1-indexed, like for editors. Otherwise this code
569641569639
would have way too many off-by-one errors *)
569642569640
let print_file
569643-
569641+
~is_warning
569644569642
(* start_line_start_char inclusive, end_line_end_char exclusive *)
569645569643
~range:((start_line, start_line_start_char), (end_line, end_line_end_char))
569646569644
~lines
@@ -569673,10 +569671,10 @@ ppf
569673569671
| Some n -> n
569674569672
in
569675569673
(* coloring *)
569676-
let highlighted_line_number : _ format = "@{<error>%s@}%a" in
569674+
let highlighted_line_number : _ format = if is_warning then "@{<info>%s@}%a" else "@{<error>%s@}%a" in
569677569675

569678569676
let print_char_maybe_highlight ~begin_highlight_line ~end_highlight_line ch =
569679-
let highlighted_open_tag: _ format = "@{<error>" in
569677+
let highlighted_open_tag: _ format = if is_warning then "@{<info>" else "@{<error>" in
569680569678
if begin_highlight_line then fprintf ppf highlighted_open_tag;
569681569679
fprintf ppf "%c@," ch;
569682569680
if end_highlight_line then fprintf ppf "@}"
@@ -569817,8 +569815,12 @@ let print_loc ~normalizedRange ppf (loc : Location.t) =
569817569815
fprintf ppf "@{<filename>%a@}%a" print_filename loc.loc_start.pos_fname dim_loc normalizedRange
569818569816
;;
569819569817

569820-
let print intro ppf (loc : Location.t) =
569821-
fprintf ppf "@[@{<error>%s@}@]@," intro;
569818+
let print ~message_kind intro ppf (loc : Location.t) =
569819+
begin match message_kind with
569820+
| `warning -> fprintf ppf "@[@{<info>%s@}@]@," intro
569821+
| `warning_as_error -> fprintf ppf "@[@{<error>%s@} (configured as error) @]@," intro
569822+
| `error -> fprintf ppf "@[@{<error>%s@}@]@," intro
569823+
end;
569822569824
(* ocaml's reported line/col numbering is horrible and super error-prone
569823569825
when being handled programmatically (or humanly for that matter. If you're
569824569826
an ocaml contributor reading this: who the heck reads the character count
@@ -569852,7 +569854,7 @@ let print intro ppf (loc : Location.t) =
569852569854
branch might not be reached (aka no inline file content display) so
569853569855
we don't wanna end up with two line breaks in the the consequent *)
569854569856
fprintf ppf "@,%a"
569855-
(Super_misc.print_file ~lines ~range)
569857+
(Super_misc.print_file ~is_warning:(message_kind=`warning) ~lines ~range)
569856569858
()
569857569859
with
569858569860
(* this might happen if the file is e.g. "", "_none_" or any of the fake file name placeholders.
@@ -569866,7 +569868,7 @@ let print intro ppf (loc : Location.t) =
569866569868
let rec super_error_reporter ppf ({loc; msg; sub} : Location.error) =
569867569869
setup_colors ();
569868569870
(* open a vertical box. Everything in our message is indented 2 spaces *)
569869-
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print "We've found a bug for you!") loc msg;
569871+
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print ~message_kind:`error "We've found a bug for you!") loc msg;
569870569872
List.iter (Format.fprintf ppf "@,@[%a@]" super_error_reporter) sub
569871569873
(* no need to flush here; location's report_exception (which uses this ultimately) flushes *)
569872569874

@@ -569876,10 +569878,11 @@ let rec super_error_reporter ppf ({loc; msg; sub} : Location.error) =
569876569878
let super_warning_printer loc ppf w =
569877569879
match Warnings.report w with
569878569880
| `Inactive -> ()
569879-
| `Active { Warnings. number = _; message = _; sub_locs = _} ->
569881+
| `Active { Warnings. number = _; message = _; is_error; sub_locs = _} ->
569880569882
setup_colors ();
569881-
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]@."
569882-
(print ("Warning number " ^ (Warnings.number w |> string_of_int)))
569883+
let message_kind = if is_error then `warning_as_error else `warning in
569884+
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]"
569885+
(print ~message_kind ("Warning number " ^ (Warnings.number w |> string_of_int)))
569883569886
loc
569884569887
(Warnings.message w);
569885569888
(* at this point, you can display sub_locs too, from e.g. https://github.com/ocaml/ocaml/commit/f6d53cc38f87c67fbf49109f5fb79a0334bab17a

lib/4.06.1/whole_compiler.ml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -435103,9 +435103,7 @@ module Super_misc : sig
435103435103
#1 "super_misc.mli"
435104435104
(** Range coordinates all 1-indexed, like for editors. Otherwise this code
435105435105
would have way too many off-by-one errors *)
435106-
val print_file:
435107-
range:(int * int) * (int * int) ->
435108-
lines:string array -> Format.formatter -> unit -> unit
435106+
val print_file: is_warning:bool -> range:(int * int) * (int * int) -> lines:string array -> Format.formatter -> unit -> unit
435109435107

435110435108
end = struct
435111435109
#1 "super_misc.ml"
@@ -435147,7 +435145,7 @@ type current_printed_line_status =
435147435145
(* Range coordinates all 1-indexed, like for editors. Otherwise this code
435148435146
would have way too many off-by-one errors *)
435149435147
let print_file
435150-
435148+
~is_warning
435151435149
(* start_line_start_char inclusive, end_line_end_char exclusive *)
435152435150
~range:((start_line, start_line_start_char), (end_line, end_line_end_char))
435153435151
~lines
@@ -435180,10 +435178,10 @@ ppf
435180435178
| Some n -> n
435181435179
in
435182435180
(* coloring *)
435183-
let highlighted_line_number : _ format = "@{<error>%s@}%a" in
435181+
let highlighted_line_number : _ format = if is_warning then "@{<info>%s@}%a" else "@{<error>%s@}%a" in
435184435182

435185435183
let print_char_maybe_highlight ~begin_highlight_line ~end_highlight_line ch =
435186-
let highlighted_open_tag: _ format = "@{<error>" in
435184+
let highlighted_open_tag: _ format = if is_warning then "@{<info>" else "@{<error>" in
435187435185
if begin_highlight_line then fprintf ppf highlighted_open_tag;
435188435186
fprintf ppf "%c@," ch;
435189435187
if end_highlight_line then fprintf ppf "@}"
@@ -435324,8 +435322,12 @@ let print_loc ~normalizedRange ppf (loc : Location.t) =
435324435322
fprintf ppf "@{<filename>%a@}%a" print_filename loc.loc_start.pos_fname dim_loc normalizedRange
435325435323
;;
435326435324

435327-
let print intro ppf (loc : Location.t) =
435328-
fprintf ppf "@[@{<error>%s@}@]@," intro;
435325+
let print ~message_kind intro ppf (loc : Location.t) =
435326+
begin match message_kind with
435327+
| `warning -> fprintf ppf "@[@{<info>%s@}@]@," intro
435328+
| `warning_as_error -> fprintf ppf "@[@{<error>%s@} (configured as error) @]@," intro
435329+
| `error -> fprintf ppf "@[@{<error>%s@}@]@," intro
435330+
end;
435329435331
(* ocaml's reported line/col numbering is horrible and super error-prone
435330435332
when being handled programmatically (or humanly for that matter. If you're
435331435333
an ocaml contributor reading this: who the heck reads the character count
@@ -435359,7 +435361,7 @@ let print intro ppf (loc : Location.t) =
435359435361
branch might not be reached (aka no inline file content display) so
435360435362
we don't wanna end up with two line breaks in the the consequent *)
435361435363
fprintf ppf "@,%a"
435362-
(Super_misc.print_file ~lines ~range)
435364+
(Super_misc.print_file ~is_warning:(message_kind=`warning) ~lines ~range)
435363435365
()
435364435366
with
435365435367
(* this might happen if the file is e.g. "", "_none_" or any of the fake file name placeholders.
@@ -435373,7 +435375,7 @@ let print intro ppf (loc : Location.t) =
435373435375
let rec super_error_reporter ppf ({loc; msg; sub} : Location.error) =
435374435376
setup_colors ();
435375435377
(* open a vertical box. Everything in our message is indented 2 spaces *)
435376-
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print "We've found a bug for you!") loc msg;
435378+
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print ~message_kind:`error "We've found a bug for you!") loc msg;
435377435379
List.iter (Format.fprintf ppf "@,@[%a@]" super_error_reporter) sub
435378435380
(* no need to flush here; location's report_exception (which uses this ultimately) flushes *)
435379435381

@@ -435383,10 +435385,11 @@ let rec super_error_reporter ppf ({loc; msg; sub} : Location.error) =
435383435385
let super_warning_printer loc ppf w =
435384435386
match Warnings.report w with
435385435387
| `Inactive -> ()
435386-
| `Active { Warnings. number = _; message = _; sub_locs = _} ->
435388+
| `Active { Warnings. number = _; message = _; is_error; sub_locs = _} ->
435387435389
setup_colors ();
435388-
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]@."
435389-
(print ("Warning number " ^ (Warnings.number w |> string_of_int)))
435390+
let message_kind = if is_error then `warning_as_error else `warning in
435391+
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]"
435392+
(print ~message_kind ("Warning number " ^ (Warnings.number w |> string_of_int)))
435390435393
loc
435391435394
(Warnings.message w);
435392435395
(* at this point, you can display sub_locs too, from e.g. https://github.com/ocaml/ocaml/commit/f6d53cc38f87c67fbf49109f5fb79a0334bab17a

0 commit comments

Comments
 (0)