From 47540c9662b5a513afbd7161f29704569cbd04fc Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Fri, 24 Apr 2020 06:22:44 -0700 Subject: [PATCH] [nullsafe][EASY] Add more logs around issue reporting Summary: They were useful when I was debugging an issue. Reviewed By: skcho Differential Revision: D21202865 fbshipit-source-id: 6ec0de9a0 --- infer/src/nullsafe/ClassLevelAnalysis.ml | 2 ++ infer/src/nullsafe/typeErr.ml | 19 +++++++++++++++++++ infer/src/nullsafe/typeErr.mli | 2 ++ 3 files changed, 23 insertions(+) diff --git a/infer/src/nullsafe/ClassLevelAnalysis.ml b/infer/src/nullsafe/ClassLevelAnalysis.ml index c8cd689e2..2333a840f 100644 --- a/infer/src/nullsafe/ClassLevelAnalysis.ml +++ b/infer/src/nullsafe/ClassLevelAnalysis.ml @@ -82,6 +82,8 @@ let make_meta_issue all_issues current_mode class_name = let issue_count_in_curr_mode = get_reportable_typing_rules_violations ~nullsafe_mode:current_mode all_issues |> List.length in + List.iter (get_reportable_typing_rules_violations ~nullsafe_mode:current_mode all_issues) + ~f:(fun issue -> Logging.debug Analysis Medium "Issue: %a@\n" TypeErr.pp_err_instance issue) ; let mode_to_promote_to = calc_mode_to_promote_to current_mode all_issues in let meta_issue_info = Jsonbug_t. diff --git a/infer/src/nullsafe/typeErr.ml b/infer/src/nullsafe/typeErr.ml index 2a2497949..ea4a2580c 100644 --- a/infer/src/nullsafe/typeErr.ml +++ b/infer/src/nullsafe/typeErr.ml @@ -9,6 +9,7 @@ open! IStd module Hashtbl = Caml.Hashtbl module MF = MarkupFormatter module P = Printf +module F = Format (** Module for Type Error messages. *) @@ -82,6 +83,22 @@ type err_instance = ; rhs_origin: TypeOrigin.t } [@@deriving compare] +let pp_err_instance fmt err_instance = + match err_instance with + | Condition_redundant _ -> + F.pp_print_string fmt "Condition_redundant" + | Inconsistent_subclass _ -> + F.pp_print_string fmt "Inconsistent_subclass" + | Field_not_initialized _ -> + F.pp_print_string fmt "Field_not_initialized" + | Over_annotation _ -> + F.pp_print_string fmt "Over_annotation" + | Nullable_dereference _ -> + F.pp_print_string fmt "Nullable_dereference" + | Bad_assignment {rhs_origin} -> + F.fprintf fmt "Bad_assignment: rhs %s" (TypeOrigin.to_string rhs_origin) + + module H = Hashtbl.Make (struct type t = err_instance * InstrRef.t option [@@deriving compare] @@ -147,6 +164,7 @@ let add_err find_canonical_duplicate err_instance instr_ref_opt loc = | _ -> instr_ref_opt in + Logging.debug Analysis Medium "Registering an issue: %a@\n" pp_err_instance err_instance ; H.add err_tbl (err_instance, instr_ref_opt_deduplicate) {loc; always= true} ; not is_forall @@ -325,6 +343,7 @@ let report_now_if_reportable (st_report_error : st_report_error) err_instance ~n let pname = Procdesc.get_proc_name pdesc in get_error_info_if_reportable ~nullsafe_mode err_instance |> Option.iter ~f:(fun (err_description, infer_issue_type, updated_location, severity) -> + Logging.debug Analysis Medium "About to report: %s" err_description ; let field_name = get_field_name_for_error_suppressing err_instance in let error_location = Option.value updated_location ~default:loc in st_report_error pname pdesc infer_issue_type error_location ~field_name diff --git a/infer/src/nullsafe/typeErr.mli b/infer/src/nullsafe/typeErr.mli index b5d28791c..6c3f1b6bd 100644 --- a/infer/src/nullsafe/typeErr.mli +++ b/infer/src/nullsafe/typeErr.mli @@ -58,6 +58,8 @@ type err_instance = ; rhs_origin: TypeOrigin.t } [@@deriving compare] +val pp_err_instance : Format.formatter -> err_instance -> unit + val node_reset_forall : Procdesc.Node.t -> unit type st_report_error =