From e5bf66b61df328fe8e419b202b58e5c37faa36ad Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Tue, 17 Sep 2024 14:35:16 +0200 Subject: [PATCH] Apply @:haxe.warning rules to cached warnings too --- src/compiler/server.ml | 4 ++-- src/context/common.ml | 6 +++--- src/context/display/deprecationCheck.ml | 8 +++----- src/context/display/diagnosticsPrinter.ml | 10 +++++++--- src/core/tType.ml | 11 ++++++++++- src/core/warning.ml | 10 +--------- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/compiler/server.ml b/src/compiler/server.ml index 22a5d8fb91b..ae76e9589a8 100644 --- a/src/compiler/server.ml +++ b/src/compiler/server.ml @@ -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 diff --git a/src/context/common.ml b/src/context/common.ml index b0662d700b2..25d17d05326 100644 --- a/src/context/common.ml +++ b/src/context/common.ml @@ -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; @@ -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 *) diff --git a/src/context/display/deprecationCheck.ml b/src/context/display/deprecationCheck.ml index 148e20294ae..584df48daf6 100644 --- a/src/context/display/deprecationCheck.ml +++ b/src/context/display/deprecationCheck.ml @@ -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 = diff --git a/src/context/display/diagnosticsPrinter.ml b/src/context/display/diagnosticsPrinter.ml index dd485713de5..6f3f7d0dd0c 100644 --- a/src/context/display/diagnosticsPrinter.ml +++ b/src/context/display/diagnosticsPrinter.ml @@ -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 -> () diff --git a/src/core/tType.ml b/src/core/tType.ml index a60b67b47b8..af3d4513b53 100644 --- a/src/core/tType.ml +++ b/src/core/tType.ml @@ -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 diff --git a/src/core/warning.ml b/src/core/warning.ml index 4cc152a577c..de010e49bbf 100644 --- a/src/core/warning.ml +++ b/src/core/warning.ml @@ -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}