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