Skip to content

Commit

Permalink
[diagnostics] avoid crash when emitting diagnostics while report mode…
Browse files Browse the repository at this point in the history
… has been disabled
  • Loading branch information
kLabz committed Jun 27, 2024
1 parent 8ec380d commit 78242ae
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ type context = {
main : context_main;
mutable package_rules : (string,package_rule) PMap.t;
mutable report_mode : report_mode;
mutable report_mode_disabled : bool;
(* communication *)
mutable print : string -> unit;
mutable error : ?depth:int -> string -> pos -> unit;
Expand Down Expand Up @@ -855,6 +856,7 @@ let create compilation_step cs version args display_mode =
json_out = None;
has_error = false;
report_mode = RMNone;
report_mode_disabled = false;
is_macro_context = false;
functional_interface_lut = new Lookup.hashtbl_lookup;
hxb_reader_api = None;
Expand All @@ -863,16 +865,19 @@ let create compilation_step cs version args display_mode =
} in
com

let is_diagnostics com = match com.report_mode with
let is_diagnostics com = not com.report_mode_disabled && match com.report_mode with
| RMLegacyDiagnostics _ | RMDiagnostics _ -> true
| _ -> false

let is_compilation com = com.display.dms_kind = DMNone && not (is_diagnostics com)

let disable_report_mode com =
let old = com.report_mode in
com.report_mode <- RMNone;
(fun () -> com.report_mode <- old)
if com.report_mode_disabled || com.report_mode = RMNone then
(fun () -> ())
else begin
com.report_mode_disabled <- true;
(fun () -> com.report_mode_disabled <- false)
end

let log com str =
if com.verbose then com.print (str ^ "\n")
Expand Down

0 comments on commit 78242ae

Please sign in to comment.