diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index 4524a30ac..7f25cdb20 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -20,8 +20,6 @@ type log_t = exn -> unit -type log_issue = Typ.Procname.t -> log_t - type log_issue_from_errlog = Errlog.t -> log_t let log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?linters_def_file exn = @@ -45,23 +43,20 @@ let log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?linters_ Errlog.log_issue err_kind err_log loc node_id session ltr ?linters_def_file exn -let log_issue - err_kind - proc_name - ?loc - ?node_id - ?session - ?ltr - ?linters_def_file - exn = - let should_suppress_lint (summary : Specs.summary) = +let log_issue_from_summary err_kind summary ?loc ?node_id ?session ?ltr ?linters_def_file exn = + let should_suppress_lint = Config.curr_language_is Config.Java && - Annotations.ia_is_suppress_lint (fst summary.attributes.ProcAttributes.method_annotation) in + Annotations.ia_is_suppress_lint + (fst summary.Specs.attributes.ProcAttributes.method_annotation) in + if not should_suppress_lint + then + let err_log = summary.Specs.attributes.ProcAttributes.err_log in + log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?linters_def_file exn + +let log_issue err_kind proc_name ?loc ?node_id ?session ?ltr ?linters_def_file exn = match Specs.get_summary proc_name with - | Some summary when should_suppress_lint summary -> () | Some summary -> - let err_log = summary.Specs.attributes.ProcAttributes.err_log in - log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?linters_def_file exn + log_issue_from_summary err_kind summary ?loc ?node_id ?session ?ltr ?linters_def_file exn | None -> failwithf "Trying to report error on procedure %a, but cannot because no summary exists for this \ @@ -69,10 +64,14 @@ let log_issue Typ.Procname.pp proc_name Typ.Procname.pp proc_name -let log_error = log_issue Exceptions.Kerror -let log_warning = log_issue Exceptions.Kwarning -let log_info = log_issue Exceptions.Kinfo - let log_error_from_errlog = log_issue_from_errlog Exceptions.Kerror let log_warning_from_errlog = log_issue_from_errlog Exceptions.Kwarning let log_info_from_errlog = log_issue_from_errlog Exceptions.Kinfo + +let log_error_from_summary = log_issue_from_summary Exceptions.Kerror +let log_warning_from_summary = log_issue_from_summary Exceptions.Kwarning +let log_info_from_summary = log_issue_from_summary Exceptions.Kwarning + +let log_error = log_issue Exceptions.Kerror +let log_warning = log_issue Exceptions.Kwarning +let log_info = log_issue Exceptions.Kinfo diff --git a/infer/src/backend/reporting.mli b/infer/src/backend/reporting.mli index 33852e1ec..e7d0b665c 100644 --- a/infer/src/backend/reporting.mli +++ b/infer/src/backend/reporting.mli @@ -20,18 +20,16 @@ type log_t = exn -> unit -type log_issue = Typ.Procname.t -> log_t - type log_issue_from_errlog = Errlog.t -> log_t (** Report an error in the given procedure. *) -val log_error : log_issue +val log_error : Typ.Procname.t -> log_t (** Report a warning in the given procedure. *) -val log_warning : log_issue +val log_warning : Typ.Procname.t -> log_t (** Report an info in the given procedure. *) -val log_info : log_issue +val log_info : Typ.Procname.t -> log_t (** Report an issue of a given kind in the given error log. *) val log_issue_from_errlog : Exceptions.err_kind -> log_issue_from_errlog @@ -44,3 +42,12 @@ val log_warning_from_errlog : log_issue_from_errlog (** Report an info in the given error log. *) val log_info_from_errlog : log_issue_from_errlog + +(** Add an error to the given summary. *) +val log_error_from_summary : Specs.summary -> log_t + +(** Add an warning to the given summary. *) +val log_warning_from_summary : Specs.summary -> log_t + +(** Add an info to the given summary. *) +val log_info_from_summary : Specs.summary -> log_t diff --git a/infer/src/checkers/fragmentRetainsViewChecker.ml b/infer/src/checkers/fragmentRetainsViewChecker.ml index fbc4c1223..87871061e 100644 --- a/infer/src/checkers/fragmentRetainsViewChecker.ml +++ b/infer/src/checkers/fragmentRetainsViewChecker.ml @@ -13,15 +13,16 @@ open! IStd module P = Printf -let report_error fragment_typ fld fld_typ pname pdesc = +let report_error fragment_typ fld fld_typ summary pdesc = + let pname = Procdesc.get_proc_name pdesc in let retained_view = "CHECKERS_FRAGMENT_RETAINS_VIEW" in let description = Localise.desc_fragment_retains_view fragment_typ fld fld_typ pname in let exn = Exceptions.Checkers (retained_view, description) in let loc = Procdesc.get_loc pdesc in - Reporting.log_error pname ~loc exn + Reporting.log_error_from_summary summary ~loc exn let callback_fragment_retains_view_java - pname_java { Callbacks.proc_desc; tenv } = + pname_java { Callbacks.proc_desc; summary; tenv } = (* TODO: complain if onDestroyView is not defined, yet the Fragment has View fields *) (* TODO: handle fields nullified in callees in the same file *) let is_on_destroy_view = String.equal (Typ.Procname.java_get_method pname_java) "onDestroyView" in @@ -46,7 +47,7 @@ let callback_fragment_retains_view_java ~f:(fun (fname, fld_typ, _) -> if not (Ident.FieldSet.mem fname fields_nullified) then report_error - (Tstruct class_typename) fname fld_typ (Typ.Procname.Java pname_java) proc_desc) + (Tstruct class_typename) fname fld_typ summary proc_desc) declared_view_fields | _ -> () end @@ -60,4 +61,4 @@ let callback_fragment_retains_view ({ Callbacks.summary } as args) : Specs.summa | _ -> () end; - Specs.get_summary_unsafe "callback_fragment_retains_view" proc_name + summary