[nullsafe] Introduce a flag for conditionally disabling field not initialized issue

Summary:
Now we can either disable it, or enable it only.
For integrations that disable it, this will allow to enable it for
NullsafeStrict classes without enabled it fully

Reviewed By: artempyanykh

Differential Revision: D19409131

fbshipit-source-id: a2b1fe650
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent 715227d126
commit 696c0e8b09

@ -1537,6 +1537,12 @@ INTERNAL OPTIONS
--nullable-annotation-name-reset
Cancel the effect of --nullable-annotation-name.
--nullsafe-disable-field-not-initialized-in-nonstrict-classes
Activates: Nullsafe: In this mode field not initialized issues
won't be reported unless the class is marked as @NullsafeStrict.
This feature is needed for compatibility reasons. (Conversely:
--no-nullsafe-disable-field-not-initialized-in-nonstrict-classes)
--no-nullsafe-optimistic-third-party-params-in-non-strict
Deactivates: Nullsafe: in this mode we treat non annotated third
party method params as if they were annotated as nullable.

@ -1742,6 +1742,12 @@ and nullable_annotation =
CLOpt.mk_string_opt ~long:"nullable-annotation-name" "Specify custom nullable annotation name"
and nullsafe_disable_field_not_initialized_in_nonstrict_classes =
CLOpt.mk_bool ~long:"nullsafe-disable-field-not-initialized-in-nonstrict-classes" ~default:false
"Nullsafe: In this mode field not initialized issues won't be reported unless the class is \
marked as @NullsafeStrict. This feature is needed for compatibility reasons."
and nullsafe_optimistic_third_party_params_in_non_strict =
CLOpt.mk_bool
~long:
@ -2981,6 +2987,10 @@ and nelseg = !nelseg
and nullable_annotation = !nullable_annotation
and nullsafe_disable_field_not_initialized_in_nonstrict_classes =
!nullsafe_disable_field_not_initialized_in_nonstrict_classes
and nullsafe_optimistic_third_party_params_in_non_strict =
!nullsafe_optimistic_third_party_params_in_non_strict

@ -484,6 +484,8 @@ val nullable_annotation : string option
val nullsafe : bool
val nullsafe_disable_field_not_initialized_in_nonstrict_classes : bool
val nullsafe_optimistic_third_party_params_in_non_strict : bool
val nullsafe_third_party_signatures : string option

@ -297,9 +297,18 @@ let check_constructor_initialization tenv find_canonical_duplicate curr_construc
is_field_declared_as_nonnull annotated_field
&& not is_initialized_in_either_constructor_or_initializer
then
report_error tenv find_canonical_duplicate
(TypeErr.Field_not_initialized {is_strict_mode; field_name})
None loc curr_constructor_pdesc ;
if
Config.nullsafe_disable_field_not_initialized_in_nonstrict_classes
&& not is_strict_mode
then
(* Behavior needed for backward compatibility, where we are not ready to surface this type of errors by default.
Hovewer, this error should be always turned on for @NullsafeStrict classes.
*)
()
else
report_error tenv find_canonical_duplicate
(TypeErr.Field_not_initialized {is_strict_mode; field_name})
None loc curr_constructor_pdesc ;
(* Check if field is over-annotated. *)
match annotated_field with
| None ->

Loading…
Cancel
Save