Redefine meaning of "void arrow functions" #33069
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-stale
Closed as the issue or PR is assumed stale
Uh oh!
There was an error while loading. Please reload this page.
The language team discussed, but did not yet commit to, the following change:
The motivation for the first rule is that it eliminates an inconsistency in the rules:
return 42;
is an error in a{}
function with return typevoid
, based on the consideration that it is too error-prone: It looks like that value is being passed on and used, but that value is actually marked as invalid ("to be discarded") by the return typevoid
.With the old semantics,
void f() => 42;
would be allowed, but it would be defined to meanvoid f() { return 42; }
which is not allowed. With the adjustment above it would meanvoid f() { 42; }
, which is allowed.The motivation for the second rule (
g
) is that it allows the concise notation using=>
to create avoid
function, which is in practice what developers want when they write functions likeg() => e;
wheree
has static typevoid
.We will need a feature specification for this, and the following topics are among the obvious ones that we have not yet considered in detail:
void foo() => e;
should returnnull
, but method signature inference should have preference (and it could then, e.g., reveal some errors because some methods would have avoid
returned expression and a non-void return type).null
is returned) would still make a difference.null
from() => print('Hello')
.Tasks:
The text was updated successfully, but these errors were encountered: