Skip to content

Allow "void" as a type argument #27504

Closed
Closed
@munificent

Description

@munificent

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 uses Future, which doesn't give you great static checking of the result, or Future<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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions