Add non-null accepting type annotations. #5545
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-duplicate
Closed in favor of an existing report
type-enhancement
A request for a change that isn't a bug
Add a tag to type annotations that make them not accept null.
A traditional syntax would be a suffix '!'. Example:
int! x = 42;
x = null;
The latter assignment would fail in checked mode, because while null is assignable to int, it's not allowed by the type assertion "int!".
This is not the same as non-nullable types. A type parameter or type expression is always a type. A type annotation is a type optionally followed by an '!', and it only affects checked mode where the type test
becomes "instance of" instead of "assignable to" for the checked mode type assertions.
It is a common use-case that a method can accept only non-null values. Currently you need to add an extra check for null.
This is ofcourse a special case of more general assertions: http://code.google.com/p/dart/issues/detail?id=3049
but one that is much less intrusive to add.
Issue created because there are wishes for something like this in the discussion of issue #22, which is about more general non-nullable types.
The text was updated successfully, but these errors were encountered: