Skip to content

Commit

Permalink
Apply @:haxe.warning rules to cached warnings too
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Sep 17, 2024
1 parent b99eda0 commit e5bf66b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ let handle_cache_bound_objects com cbol =
Hashtbl.replace com.resources name data
| IncludeFile(file,position) ->
com.include_files <- (file,position) :: com.include_files
| Warning(w,msg,p) ->
com.warning w [] msg p
| Warning(w,options,msg,p) ->
com.warning w options msg p
) cbol

(* Adds module [m] and all its dependencies (recursively) from the cache to the current compilation
Expand Down
6 changes: 3 additions & 3 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ type context = {
mutable error : ?depth:int -> string -> pos -> unit;
mutable error_ext : Error.error -> unit;
mutable info : ?depth:int -> ?from_macro:bool -> string -> pos -> unit;
mutable warning : ?depth:int -> ?from_macro:bool -> warning -> Warning.warning_option list list -> string -> pos -> unit;
mutable warning_options : Warning.warning_option list list;
mutable warning : ?depth:int -> ?from_macro:bool -> warning -> warning_option list list -> string -> pos -> unit;
mutable warning_options : warning_option list list;
mutable get_messages : unit -> compiler_message list;
mutable filter_messages : (compiler_message -> bool) -> unit;
mutable run_command : string -> int;
Expand Down Expand Up @@ -443,7 +443,7 @@ let ignore_error com =
b

let module_warning com m w options msg p =
if com.display.dms_full_typing then DynArray.add m.m_extra.m_cache_bound_objects (Warning(w,msg,p));
if com.display.dms_full_typing then DynArray.add m.m_extra.m_cache_bound_objects (Warning(w,options,msg,p));
com.warning w options msg p

(* Defines *)
Expand Down
8 changes: 3 additions & 5 deletions src/context/display/deprecationCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ let warned_positions = Hashtbl.create 0
let warn_deprecation dctx s p_usage =
let pkey p = (p.pfile,p.pmin) in
if not (Hashtbl.mem warned_positions (pkey p_usage)) then begin
Hashtbl.add warned_positions (pkey p_usage) (s,p_usage);
if not (is_diagnostics dctx.com) then begin
let options = Warning.from_meta (dctx.class_meta @ dctx.field_meta) in
module_warning dctx.com dctx.curmod WDeprecated options s p_usage;
end
let options = Warning.from_meta (dctx.class_meta @ dctx.field_meta) in
Hashtbl.add warned_positions (pkey p_usage) (s,p_usage,options);
module_warning dctx.com dctx.curmod WDeprecated options s p_usage;
end

let print_deprecation_message dctx meta s p_usage =
Expand Down
10 changes: 7 additions & 3 deletions src/context/display/diagnosticsPrinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ let json_of_diagnostics com dctx =
(* non-append from here *)
begin match Warning.get_mode WDeprecated com.warning_options with
| WMEnable ->
Hashtbl.iter (fun _ (s,p) ->
let wobj = Warning.warning_obj WDeprecated in
add DKDeprecationWarning p MessageSeverity.Warning (Some wobj.w_name) (JString s);
Hashtbl.iter (fun _ (s,p,options) ->
begin match Warning.get_mode WDeprecated (com.warning_options @ options) with
| WMEnable ->
let wobj = Warning.warning_obj WDeprecated in
add DKDeprecationWarning p MessageSeverity.Warning (Some wobj.w_name) (JString s);
| WMDisable -> ()
end
) DeprecationCheck.warned_positions;
| WMDisable ->
()
Expand Down
11 changes: 10 additions & 1 deletion src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,19 @@ type type_param_host =
| TPHLocal
| TPHUnbound

type warning_mode =
| WMEnable
| WMDisable

type warning_option = {
wo_warning : WarningList.warning;
wo_mode : warning_mode;
}

type cache_bound_object =
| Resource of string * string
| IncludeFile of string * string
| Warning of WarningList.warning * string * pos
| Warning of WarningList.warning * (warning_option list list) * string * pos

type t =
| TMono of tmono
Expand Down
10 changes: 1 addition & 9 deletions src/core/warning.ml
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
open Globals
open Error
open TType
include WarningList

type warning_mode =
| WMEnable
| WMDisable

type warning_option = {
wo_warning : warning;
wo_mode : warning_mode;
}

let parse_options s ps lexbuf =
let fail msg p =
raise_typing_error msg {p with pmin = ps.pmin + p.pmin; pmax = ps.pmin + p.pmax}
Expand Down

0 comments on commit e5bf66b

Please sign in to comment.