Initial analyzer NNBD prototype

For the D24 release, we are planning to prototype the following non-nullable-by-default features:

  • Opt in/out mechanism for individual libraries via @dart=<version> in source files
  • Opt in/out mechanism for packages via #dart=<version> and *:<package-name> in .package files
  • Trailing ? on types
  • Trailing ! on expressions
  • late modifier
  • required function parameters
  • Error checking for use of nullable value in a non-nullable context
  • Hints for unnecessary null checks
  • Prohibit implicit downcasts
  • Type Never

The following features will be included if time allows:

  • Apply opt in/out mechanism to past language features
  • Null-aware array indexing

The following features are out of scope for the D24 release:

  • Migrated SDK
  • Changes to behavior of short-circuiting operators
  • Rework type assignability checking to operate on all subexpressions
  • Fix Strong mode type promoted bounds should not be inferred in reified positions #30832
  • Add an InvalidType
  • Definite assignment analysis
  • Improved type promotion
  • Improved reachability analysis

Author: Fantashit

1 thought on “Initial analyzer NNBD prototype

  1. Here’s what’s currently believed to work in the analyzer prototype:

    • Enable/disable and opt in/out mechanism: @dart=<version> is handled in library and part files. It is not recognized in .package files.
    • All NNBD syntax is recognized except for null-aware array indexing (a?.[b]) and trailing ? on function-typed parameters.
    • Summaries are mostly working, but there are issues with top level type inference.
    • The postfix ! operator is recognized, and its behaviors are mostly correct, but type inference has not been fully verified.
    • Nullability behaviors for ?? and ??= are implemented, but there are some cases with type parameter types that haven’t been fully verified.
    • The late modifier should work.
    • The required modifier is recognized syntactially, but not plumbed through the type system.
    • Expressions of the form a && b, a || b, !a, a is b, and a == b are understood to have non-null types.
    • Downward inference is being worked on, but it hasn’t been verified that it passes down context with the correct nullability.
    • Subtype checking is mostly implemented, but there are some corner cases that are still known to be incorrect. The “try subtype match” algorithm in type inference may also need work.
    • We believe instantiate-to-bounds is correct but we haven’t confirmed.
    • Implicit downcasts are prohibited when NNBD is enabled.
    • The new Never type is supported.
    • Most new error conditions related to NNBD are properly reported, but not all.

    Here’s what’s not working:

    • The SDK is not migrated.
    • Short-circuiting behavior for ?.
    • Least upper bound hasn’t been modified for NNBD yet.
    • We haven’t evaluated whether changes need to be made to the “flatten” algorithm for futures.
    • We don’t yet issue hints or lints related to NNBD (e.g. boolean expressions whose value can be deduced based on nullability, or the use of a non-nullable type as the operand of ??, postfix !, etc.)
    • Definite assignment analysis is not yet implemented.
    • Type promotion improvements are not yet implemented.
    • Improvements to reachability analysis are not yet implemented.

Comments are closed.