[nullsafe][TypeOrigin refactor] introduce TypeOrigin.ArrayLengthResult

Summary:
This diff is a part of work teaching Nullsafe to explain decisions it's
making.

Using `New` was definitely not a good idea here, we need a specific
data type value here.

Reviewed By: artempyanykh

Differential Revision: D18450174

fbshipit-source-id: 7ce7cc7e8
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent 4a81a69fb3
commit 8e3f1b33b5

@ -1094,7 +1094,7 @@ let typecheck_instr tenv calls_this checks (node : Procdesc.Node.t) idenv curr_p
EradicateChecks.check_object_dereference ~is_strict_mode tenv find_canonical_duplicate EradicateChecks.check_object_dereference ~is_strict_mode tenv find_canonical_duplicate
curr_pdesc node instr_ref array_exp DereferenceRule.ArrayLengthAccess ta loc ; curr_pdesc node instr_ref array_exp DereferenceRule.ArrayLengthAccess ta loc ;
TypeState.add_id id TypeState.add_id id
(Typ.mk (Tint Typ.IInt), InferredNullability.create_nonnull TypeOrigin.New) (Typ.mk (Tint Typ.IInt), InferredNullability.create_nonnull TypeOrigin.ArrayLengthResult)
typestate typestate
(* All other builtins that are not considered above *) (* All other builtins that are not considered above *)
| Sil.Call (_, Exp.Const (Const.Cfun pn), _, _, _) when BuiltinDecl.is_declared pn -> | Sil.Call (_, Exp.Const (Const.Cfun pn), _, _, _) when BuiltinDecl.is_declared pn ->

@ -23,6 +23,7 @@ type t =
| Formal of Mangled.t (** A formal parameter *) | Formal of Mangled.t (** A formal parameter *)
| Proc of proc_origin (** A procedure call *) | Proc of proc_origin (** A procedure call *)
| New (** A new object creation *) | New (** A new object creation *)
| ArrayLengthResult (** integer value - result of accessing array.length *)
| ONone (** No origin is known *) | ONone (** No origin is known *)
| Undef (** Undefined value before initialization *) | Undef (** Undefined value before initialization *)
[@@deriving compare] [@@deriving compare]
@ -42,6 +43,8 @@ let rec to_string = function
Printf.sprintf "Fun %s" (Typ.Procname.to_simplified_string po.pname) Printf.sprintf "Fun %s" (Typ.Procname.to_simplified_string po.pname)
| New -> | New ->
"New" "New"
| ArrayLengthResult ->
"ArrayLength"
| ONone -> | ONone ->
"ONone" "ONone"
| Undef -> | Undef ->
@ -76,7 +79,7 @@ let get_description origin =
But for these issues we currently don't print origins in the error string. But for these issues we currently don't print origins in the error string.
It is a good idea to change this and start printing origins for these origins as well. It is a good idea to change this and start printing origins for these origins as well.
*) *)
| New | NonnullConst _ -> | New | NonnullConst _ | ArrayLengthResult ->
None None
(* Two special cases - should not really occur in normal code *) (* Two special cases - should not really occur in normal code *)
| ONone | Undef -> | ONone | Undef ->

@ -22,6 +22,7 @@ type t =
| Formal of Mangled.t (** A formal parameter *) | Formal of Mangled.t (** A formal parameter *)
| Proc of proc_origin (** A procedure call *) | Proc of proc_origin (** A procedure call *)
| New (** A new object creation *) | New (** A new object creation *)
| ArrayLengthResult (** integer value - result of accessing array.length *)
| ONone (** No origin is known *) | ONone (** No origin is known *)
| Undef (** Undefined value before initialization *) | Undef (** Undefined value before initialization *)
[@@deriving compare] [@@deriving compare]

Loading…
Cancel
Save