[nullsafe][refactor] Use ThirdPartyNonnull instead of heuristic in error rendering

Summary:
Since artempyanykh introduced proper type for third party methods, we don't need
to write a sketchy heuristic in this place.

This will simplify shipping a feature in the follow up diff (otherwise
it would break here).

Reviewed By: artempyanykh

Differential Revision: D20139460

fbshipit-source-id: 00144dc48
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent 9a38987929
commit 2aea7d1304

@ -101,7 +101,6 @@ let mk_coming_from nullsafe_mode nullability =
let mk_recommendation nullsafe_mode nullability what = let mk_recommendation nullsafe_mode nullability what =
match (nullsafe_mode, nullability) with match (nullsafe_mode, nullability) with
| NullsafeMode.Strict, Nullability.ThirdPartyNonnull
| NullsafeMode.Strict, Nullability.UncheckedNonnull | NullsafeMode.Strict, Nullability.UncheckedNonnull
| NullsafeMode.Strict, Nullability.LocallyCheckedNonnull -> | NullsafeMode.Strict, Nullability.LocallyCheckedNonnull ->
Some (F.sprintf "make %s nullsafe strict" what) Some (F.sprintf "make %s nullsafe strict" what)
@ -130,29 +129,34 @@ let get_info object_origin nullsafe_mode bad_nullability =
(Procname.to_simplified_string ~withclass:true pname) (Procname.to_simplified_string ~withclass:true pname)
in in
let object_loc = call_loc in let object_loc = call_loc in
let suggested_third_party_sig_file =
ThirdPartyAnnotationInfo.lookup_related_sig_file_for_proc
(ThirdPartyAnnotationGlobalRepo.get_repo ())
pname
in
let what_is_used = "Result of this call" in let what_is_used = "Result of this call" in
(* Two main cases: it is either FB owned code or third party.
We determine the difference based on presense of suggested_third_party_sig_file.
*)
let+ coming_from_explanation, recommendation, issue_type = let+ coming_from_explanation, recommendation, issue_type =
match suggested_third_party_sig_file with match bad_nullability with
| Some sig_file_name -> | Nullability.Null | Nullability.Nullable ->
(* Dereferences or assignment violations with regular Nullables (* This method makes sense only for non-nullable violations *)
should not be special cased *) None
if Nullability.equal Nullable bad_nullability then None | Nullability.StrictNonnull ->
else (* This method makes sense only for non-nullable violations *)
return Logging.die InternalError "There should not be type violations involving StrictNonnull"
( "not vetted third party methods" | Nullability.ThirdPartyNonnull ->
, F.sprintf "add the correct signature to %s" let suggested_third_party_sig_file =
(ThirdPartyAnnotationGlobalRepo.get_user_friendly_third_party_sig_file_name ThirdPartyAnnotationInfo.lookup_related_sig_file_for_proc
~filename:sig_file_name) (ThirdPartyAnnotationGlobalRepo.get_repo ())
, IssueType.eradicate_unvetted_third_party_in_nullsafe ) pname
| None -> in
let where_to_add_signature =
Option.value_map suggested_third_party_sig_file
~f:(fun sig_file_name ->
ThirdPartyAnnotationGlobalRepo.get_user_friendly_third_party_sig_file_name
~filename:sig_file_name )
(* this can happen when third party is registered in a deprecated way (not in third party repository) *)
~default:"the third party signature storage"
in
return
( "not vetted third party methods"
, F.sprintf "add the correct signature to %s" where_to_add_signature
, IssueType.eradicate_unvetted_third_party_in_nullsafe )
| Nullability.UncheckedNonnull | Nullability.LocallyCheckedNonnull ->
let* from = mk_coming_from nullsafe_mode bad_nullability in let* from = mk_coming_from nullsafe_mode bad_nullability in
let+ recommendation = let+ recommendation =
let what_to_strictify = let what_to_strictify =

@ -19,9 +19,11 @@ val mk_special_nullsafe_issue :
-> bad_usage_location:Location.t -> bad_usage_location:Location.t
-> TypeOrigin.t -> TypeOrigin.t
-> (string * IssueType.t * Location.t) option -> (string * IssueType.t * Location.t) option
(** Situation when we tried to use nonnull values of incompatible modes. This is disallowed in (** Situation when we tried to use nonnull values in a nullsafe mode that does not trust them to be
strict and local mode. Returns a tuple (error message, issue type, error location). NOTE: non-nullable. From the user perspective, this case is different from normal nullable assignment
Location of the error will be NOT in the place when the value is used (that is or dereference violation: what needs to be described is why does not this mode trust this value
(and what are possible actions). Returns a tuple (error message, issue type, error location).
NOTE: Location of the error will be NOT in the place when the value is used (that is
[bad_usage_location]), but where the value is first obtained from. *) [bad_usage_location]), but where the value is first obtained from. *)
val find_alternative_nonnull_method_description : TypeOrigin.t -> string option val find_alternative_nonnull_method_description : TypeOrigin.t -> string option

Loading…
Cancel
Save