Skip to content

Should the migration to NNBD include eliminating implicit downcasts? #192

@leafpetersen

Description

@leafpetersen

Dart 2.0 assignability allows an assignment from something of type A to something of type B if A is a subtype of B or if B is a subtype of A. With non-nullable types, the implication would be that assignment of a nullable variable to a non-nullable variable would be silently accepted. This seems very contrary to the spirit of the NNBD change, and is inconsistent with what we expect from other languages.

One possible solution is to special case non-nullability with respect to assignability. For example, add a side condition that B must be nullable if A is.

An alternative is to take this opportunity to remove implicit downcasts from the language entirely as part of the NNBD opt in. Implicit downcasts seem to be a common source of confusion since they push a surprising amount of type checking to runtime. See background issues below for more discussion.

Topic specific discussion issues:

Background issues:

dart-lang/sdk#33749
dart-lang/sdk#31410
dart-lang/sdk#30402
dart-lang/sdk#32661
dart-lang/sdk#25368
dart-lang/sdk#29718
dart-lang/sdk#30385
dart-lang/sdk#29547
dart-lang/sdk#29548

Metadata

Metadata

Assignees

No one assigned

    Labels

    nnbdNNBD related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions