@ -41,8 +41,8 @@ let get_non_virtual_params {params} =
(* get nullability of method's return type given its annotations and information about its params *)
(* get nullability of method's return type given its annotations and information about its params *)
let nullability_for_return ~ is_callee_in_trust_list ~ nullsafe_mode ~ is_third_party ret_type
let nullability_for_return ~ proc_name ~ is_callee_in_trust_list ~ nullsafe_mode ~ is_third_party
ret_annotations ~ has_propagates_nullable_in_param =
~ is_provisional_annotation_mode ret_type ret_annotations ~ has_propagates_nullable_in_param =
let nullability =
let nullability =
AnnotatedNullability . of_type_and_annotation ~ is_callee_in_trust_list ~ nullsafe_mode
AnnotatedNullability . of_type_and_annotation ~ is_callee_in_trust_list ~ nullsafe_mode
~ is_third_party ret_type ret_annotations
~ is_third_party ret_type ret_annotations
@ -54,18 +54,37 @@ let nullability_for_return ~is_callee_in_trust_list ~nullsafe_mode ~is_third_par
| _ when has_propagates_nullable_in_param ->
| _ when has_propagates_nullable_in_param ->
(* if any params is propagates nullable, the return type can be only nullable *)
(* if any params is propagates nullable, the return type can be only nullable *)
AnnotatedNullability . Nullable AnnotatedNullability . HasPropagatesNullableInParam
AnnotatedNullability . Nullable AnnotatedNullability . HasPropagatesNullableInParam
| _ when is_provisional_annotation_mode ->
(* Not explicitly annotated with [@Nullable] - make it provisionally nullable *)
AnnotatedNullability . ProvisionallyNullable ( ProvisionalAnnotation . Method proc_name )
| _ ->
nullability
let nullability_for_param ~ proc_name ~ param_num ~ is_callee_in_trust_list ~ nullsafe_mode
~ is_third_party ~ is_provisional_annotation_mode param_type param_annotations =
let nullability =
AnnotatedNullability . of_type_and_annotation ~ is_callee_in_trust_list ~ nullsafe_mode
~ is_third_party param_type param_annotations
in
match nullability with
| AnnotatedNullability . Nullable _ ->
nullability
| _ when is_provisional_annotation_mode ->
AnnotatedNullability . ProvisionallyNullable
( ProvisionalAnnotation . Param { method_info = proc_name ; num = param_num } )
| _ ->
| _ ->
nullability
nullability
(* Given annotations for method signature, extract nullability information
(* Given annotations for method signature, extract nullability information
for return type and params * )
for return type and params * )
let extract_nullability ~ is_callee_in_trust_list ~ nullsafe_mode ~ is_third_party ret_type
let extract_nullability ~ proc_name ~ is_callee_in_trust_list ~ nullsafe_mode ~ is_third_party
ret_annotations param_annotated_types =
~ is_provisional_annotation_mode ret_type ret_annotations param_annotated_types =
let params_nullability =
let params_nullability =
List . map param_annotated_types ~ f : ( fun ( typ , annotations ) ->
List . map i param_annotated_types ~ f : ( fun param_num ( param_ type , param_ annotations) ->
AnnotatedNullability . of_type_and_annotation ~ is_callee_in_trust_list ~ nullsafe_mode
nullability_for_param ~ proc_name ~ param_num ~ is_callee_in_trust_list ~ nullsafe_mode
~ is_third_party typ annotations )
~ is_third_party ~ is_provisional_annotation_mode param_ type param_ annotations )
in
in
let has_propagates_nullable_in_param =
let has_propagates_nullable_in_param =
List . exists params_nullability ~ f : ( function
List . exists params_nullability ~ f : ( function
@ -75,13 +94,13 @@ let extract_nullability ~is_callee_in_trust_list ~nullsafe_mode ~is_third_party
false )
false )
in
in
let return_nullability =
let return_nullability =
nullability_for_return ~ is_callee_in_trust_list ~ nullsafe_mode ~ is_third_party ret_type
nullability_for_return ~ proc_name ~ is_callee_in_trust_list ~ nullsafe_mode ~ is_third_party
ret_ annotations ~ has_propagates_nullable_in_param
ret_ type ~ is_provisional_annotation_mode ret_ annotations ~ has_propagates_nullable_in_param
in
in
( return_nullability , params_nullability )
( return_nullability , params_nullability )
let get ~ is_callee_in_trust_list ~ nullsafe_mode
let get _impl ~ is_callee_in_trust_list ~ nullsafe_mode ~ is_provisional_annotation_mode
( { ProcAttributes . proc_name ; ret_type ; method_annotation = { return = ret_annotation } } as
( { ProcAttributes . proc_name ; ret_type ; method_annotation = { return = ret_annotation } } as
proc_attributes ) : t =
proc_attributes ) : t =
let proc_name =
let proc_name =
@ -98,8 +117,8 @@ let get ~is_callee_in_trust_list ~nullsafe_mode
List . map params_with_annotations ~ f : ( fun ( ( _ , typ ) , annotations ) -> ( typ , annotations ) )
List . map params_with_annotations ~ f : ( fun ( ( _ , typ ) , annotations ) -> ( typ , annotations ) )
in
in
let return_nullability , params_nullability =
let return_nullability , params_nullability =
extract_nullability ~ is_callee_in_trust_list ~ nullsafe_mode ~ is_third_party ret_type
extract_nullability ~ proc_name ~ is_callee_in_trust_list ~ nullsafe_mode ~ is_third_party
ret_annotation param_annotated_types
~ is_provisional_annotation_mode ret_type ret_annotation param_annotated_types
in
in
let ret =
let ret =
{ ret_annotation_deprecated = ret_annotation
{ ret_annotation_deprecated = ret_annotation
@ -116,6 +135,8 @@ let get ~is_callee_in_trust_list ~nullsafe_mode
{ nullsafe_mode ; kind ; ret ; params }
{ nullsafe_mode ; kind ; ret ; params }
let get = get_impl ~ is_provisional_annotation_mode : false
let get_for_class_under_analysis tenv proc_attributes =
let get_for_class_under_analysis tenv proc_attributes =
(* Signature makes special meaning when the method is inside the class we are currently analysing.
(* Signature makes special meaning when the method is inside the class we are currently analysing.
Various non - nullable levels ( as dictated by nullsafe mode of the class )
Various non - nullable levels ( as dictated by nullsafe mode of the class )
@ -125,7 +146,8 @@ let get_for_class_under_analysis tenv proc_attributes =
We achieve it via passing Strict mode to the signature extractor .
We achieve it via passing Strict mode to the signature extractor .
* )
* )
let result =
let result =
get ~ is_callee_in_trust_list : false ~ nullsafe_mode : NullsafeMode . Strict proc_attributes
get_impl ~ is_callee_in_trust_list : false ~ nullsafe_mode : NullsafeMode . Strict proc_attributes
~ is_provisional_annotation_mode : Config . nullsafe_annotation_graph
in
in
(* Don't forget about the original mode *)
(* Don't forget about the original mode *)
let nullsafe_mode = NullsafeMode . of_procname tenv proc_attributes . ProcAttributes . proc_name in
let nullsafe_mode = NullsafeMode . of_procname tenv proc_attributes . ProcAttributes . proc_name in