Closed
Description
The language will change to allow void
as a type argument in generics (and as a type annotation in general).
This comes up in cases like:
- A function that returns nothing asynchronously could return
Future<void>
. Today, code either usesFuture
, which doesn't give you great static checking of the result, orFuture<Null>
, which is kind of unfamiliar to most users. - Generic visitor classes that are parametric on their visit methods' return types. If you want to create a visitor that returns nothing, it would be nice to be able to explicitly extend
AstVisitor<void>
.
We also allow void
to be the type annotation for locals, parameters, fields, ...
In Dart 1, void
should simply be treated like Object
, except as a return type for function types (where the old behavior should be kept).
In strong mode, an additional "voidness" rule will disallow assignments from void
to Object
when the assignment is statically visible. We will update the bug when we have a document ready.