@ -16,8 +16,8 @@ module F = Format
type t =
type t =
| Nullable of nullable_origin
| Nullable of nullable_origin
| DeclaredNonnull of declar ed_nonnull_origin (* * See {!Nullability.t} for explanation *)
| UncheckedNonnull of uncheck ed_nonnull_origin (* * See {!Nullability.t} for explanation *)
| Nonnull of nonnull_origin
| Strict Nonnull of strict_ nonnull_origin
[ @@ deriving compare ]
[ @@ deriving compare ]
and nullable_origin =
and nullable_origin =
@ -31,7 +31,7 @@ and nullable_origin =
| ModelledNullable (* * nullsafe knows it is nullable via its internal models *)
| ModelledNullable (* * nullsafe knows it is nullable via its internal models *)
[ @@ deriving compare ]
[ @@ deriving compare ]
and declar ed_nonnull_origin =
and uncheck ed_nonnull_origin =
| AnnotatedNonnull
| AnnotatedNonnull
(* * The type is explicitly annotated as non nullable via one of nonnull annotations Nullsafe
(* * The type is explicitly annotated as non nullable via one of nonnull annotations Nullsafe
recognizes * )
recognizes * )
@ -39,7 +39,7 @@ and declared_nonnull_origin =
(* * Infer was run in mode where all not annotated ( non local ) types are treated as non
(* * Infer was run in mode where all not annotated ( non local ) types are treated as non
nullable * )
nullable * )
and nonnull_origin =
and strict_ nonnull_origin =
| ModelledNonnull (* * nullsafe knows it is non-nullable via its internal models *)
| ModelledNonnull (* * nullsafe knows it is non-nullable via its internal models *)
| StrictMode (* * under strict mode we consider non-null declarations to be trusted *)
| StrictMode (* * under strict mode we consider non-null declarations to be trusted *)
| PrimitiveType (* * Primitive types are non-nullable by language design *)
| PrimitiveType (* * Primitive types are non-nullable by language design *)
@ -50,10 +50,10 @@ and nonnull_origin =
let get_nullability = function
let get_nullability = function
| Nullable _ ->
| Nullable _ ->
Nullability . Nullable
Nullability . Nullable
| Declar edNonnull _ ->
| Uncheck edNonnull _ ->
Nullability . Declar edNonnull
Nullability . Uncheck edNonnull
| Nonnull _ ->
| Strict Nonnull _ ->
Nullability . Nonnull
Nullability . Strict Nonnull
let pp fmt t =
let pp fmt t =
@ -85,21 +85,21 @@ let pp fmt t =
match t with
match t with
| Nullable origin ->
| Nullable origin ->
F . fprintf fmt " Nullable[%s] " ( string_of_nullable_origin origin )
F . fprintf fmt " Nullable[%s] " ( string_of_nullable_origin origin )
| Declar edNonnull origin ->
| Uncheck edNonnull origin ->
F . fprintf fmt " Declar edNonnull[%s]" ( string_of_declared_nonnull_origin origin )
F . fprintf fmt " Uncheck edNonnull[%s]" ( string_of_declared_nonnull_origin origin )
| Nonnull origin ->
| Strict Nonnull origin ->
F . fprintf fmt " Nonnull[%s]" ( string_of_nonnull_origin origin )
F . fprintf fmt " Strict Nonnull[%s]" ( string_of_nonnull_origin origin )
let of_type_and_annotation ~ is_strict_mode typ annotations =
let of_type_and_annotation ~ is_strict_mode typ annotations =
if not ( PatternMatch . type_is_class typ ) then Nonnull PrimitiveType
if not ( PatternMatch . type_is_class typ ) then Strict Nonnull PrimitiveType
else if Annotations . ia_is_nullable annotations then
else if Annotations . ia_is_nullable annotations then
let nullable_origin =
let nullable_origin =
if Annotations . ia_is_propagates_nullable annotations then AnnotatedPropagatesNullable
if Annotations . ia_is_propagates_nullable annotations then AnnotatedPropagatesNullable
else AnnotatedNullable
else AnnotatedNullable
in
in
Nullable nullable_origin
Nullable nullable_origin
else if is_strict_mode then Nonnull StrictMode
else if is_strict_mode then Strict Nonnull StrictMode
else if Annotations . ia_is_nonnull annotations then Declar edNonnull AnnotatedNonnull
else if Annotations . ia_is_nonnull annotations then Uncheck edNonnull AnnotatedNonnull
(* Currently, we treat not annotated types as nonnull *)
(* Currently, we treat not annotated types as nonnull *)
else Declar edNonnull ImplicitlyNonnull
else Uncheck edNonnull ImplicitlyNonnull