Summary: In nutshell, Nullsafe is driven by relatively simple set of rules. It is currently not well reflected in code: we are duplicating the same logic in different places, which is: - error prone (we need to adjust ensure all places are addressed if a new feature is introduced) - complicates understanding of nullsafe Consolidating checks will simplify introducing Unknown Nullability and strict/partial check modes. ## this diff This diff does it for one particular check. See follow up diffs re that proceed consolidation. ## future diffs Future diffs will: - consolidate other checks that use 'assignment rule' - introduce other rules, most notably 'dereference rule' and 'inheritance rule' Reviewed By: artempyanykh Differential Revision: D17498630 fbshipit-source-id: 079d36518master
parent
74c8629d13
commit
e24cf9f155
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*)
|
||||
|
||||
open! IStd
|
||||
|
||||
let is_nonnull nullsafe_nullability =
|
||||
match nullsafe_nullability with
|
||||
| NullsafeType.Nullable _ ->
|
||||
false
|
||||
| NullsafeType.Nonnull _ ->
|
||||
true
|
||||
|
||||
|
||||
let passes_assignment_rule ~lhs ~rhs =
|
||||
(not (is_nonnull lhs)) || not (InferredNullability.is_nullable rhs)
|
@ -0,0 +1,24 @@
|
||||
(*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*)
|
||||
|
||||
open! IStd
|
||||
|
||||
(** This is a single place consolidating core rules driving Nullsafe type checking.
|
||||
Nullsafe enforces similar rules in different places (e.g. places dealing with fields,
|
||||
function calls, assignments, local variables etc.).
|
||||
Those places might have additional specifics, but core checks should be done through this class.
|
||||
If you are writing a new or modifying an existing check, ask yourself if you can directly
|
||||
use already existng rules from this module.
|
||||
If you feel you need a rule of a completely new nature, add it to this module.
|
||||
As a rule of thumb, every different "check" that is responsible for detecting issues, should query
|
||||
this module instead of doing things on their own.
|
||||
*)
|
||||
|
||||
val passes_assignment_rule : lhs:NullsafeType.nullability -> rhs:InferredNullability.t -> bool
|
||||
(** Assignment rule: No expression of nullable type is ever assigned to a location
|
||||
of non-nullable type.
|
||||
*)
|
Loading…
Reference in new issue