Only propagate nullable to return value when environment variable is set.

Reviewed By: jeremydubreil

Differential Revision: D2852820

fb-gh-sync-id: f9d52ce
master
Cristiano Calcagno 9 years ago committed by facebook-github-bot-5
parent 97a3aa3d0b
commit 453709c3c8

@ -154,21 +154,3 @@ let do_analysis curr_pdesc proc_name =
end
| _ ->
() (* skipping *)
(** Mark the return type @Nullable by modifying the spec. *)
let proc_add_return_nullable curr_pname =
match Specs.get_summary curr_pname with
| Some summary ->
let proc_attributes = Specs.get_attributes summary in
let method_annotation = proc_attributes.ProcAttributes.method_annotation in
let method_annotation' = Annotations.method_annotation_mark_return
Annotations.Nullable method_annotation in
let proc_attributes' =
{ proc_attributes with
ProcAttributes.method_annotation = method_annotation' } in
let summary' =
{ summary with
Specs.attributes = proc_attributes' } in
Specs.add_summary curr_pname summary'
| None -> ()

@ -34,9 +34,6 @@ val one_cluster_per_procedure : unit -> bool
(** Check if the procedure called by the current pdesc needs to be analyzed. *)
val procedure_should_be_analyzed : Cfg.Procdesc.t -> Procname.t -> bool
(** Mark the return type @Nullable by modifying the spec. *)
val proc_add_return_nullable : Procname.t -> unit
(** Set the callbacks used to perform on-demand analysis. *)
val set_callbacks : callbacks -> unit

@ -27,6 +27,10 @@ let activate_field_over_annotated = Config.from_env_variable "ERADICATE_FIELD_OV
(* activate the return over annotated warning *)
let activate_return_over_annotated = Config.from_env_variable "ERADICATE_RETURN_OVER_ANNOTATED"
(* activate the propagation of nullable to the return value *)
let activate_propagate_return_nullable =
Config.from_env_variable "ERADICATE_PROPAGATE_RETURN_NULLABLE"
(* do not report RETURN_NOT_NULLABLE if the return is annotated @Nonnull *)
let return_nonnull_silent = true
@ -325,6 +329,23 @@ let check_constructor_initialization
| _ -> ()
end
(** Make the return type @Nullable by modifying the spec. *)
let spec_make_return_nullable curr_pname =
match Specs.get_summary curr_pname with
| Some summary ->
let proc_attributes = Specs.get_attributes summary in
let method_annotation = proc_attributes.ProcAttributes.method_annotation in
let method_annotation' = Annotations.method_annotation_mark_return
Annotations.Nullable method_annotation in
let proc_attributes' =
{ proc_attributes with
ProcAttributes.method_annotation = method_annotation' } in
let summary' =
{ summary with
Specs.attributes = proc_attributes' } in
Specs.add_summary curr_pname summary'
| None -> ()
(** Check the annotations when returning from a method. *)
let check_return_annotation
find_canonical_duplicate curr_pname curr_pdesc exit_node ret_range
@ -352,10 +373,13 @@ let check_return_annotation
activate_return_over_annotated in
if return_not_nullable && Models.Inference.enabled then
Models.Inference.proc_add_return_nullable curr_pname;
Models.Inference.proc_mark_return_nullable curr_pname;
if return_not_nullable && !Config.ondemand_enabled then
Ondemand.proc_add_return_nullable curr_pname;
if return_not_nullable &&
!Config.ondemand_enabled &&
activate_propagate_return_nullable
then
spec_make_return_nullable curr_pname;
if return_not_nullable || return_value_not_present then
begin

@ -66,7 +66,7 @@ module Inference = struct
mark_file_count dir fname
(** Mark the return type @Nullable indirectly by writing to a global file. *)
let proc_add_return_nullable pn =
let proc_mark_return_nullable pn =
let dir, fname = proc_get_ret_dir_fname pn in
mark_file_count dir fname

Loading…
Cancel
Save