Skip to content

Make "void" arguments syntactically optional? #34176

Open
@MichaelRFairhurst

Description

@MichaelRFairhurst

Instead of

Future<void>().then((_) { ... });
Completer<void>().complete(null);
Stream.listen((_) { ... });
new StreamController().add(null);

Could we make it possible to write just

Future<void>().then(() { ... });
Completer<void>().complete();
Stream.listen(() { ... });
new StreamController().add();

?

Some tendrils I can think of here:

  • Does this mean void Function(void) is a subtype of void Function() ? (thought: no, because its not ABI compatible)
  • If not, how can () -> R be assignable to (T) -> R in Future.then?
  • If () {} is inferred as (void) -> R, is there a way to write this explicitly? Is (void _) {} close enough?
  • won't handle Function(..., void, ..., T)
  • cardinality of functions becomes no longer a single answer (Function(void, void, void) would have four different cardinalities -- everything from 0 to 3)
  • adding a new way of doing the same thing is not as good as having one excellent method. But I don't think this could replace the alternative

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).language-discussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions