You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the current spec, only void, dynamic and Null allow for return;. I'd like to add FutureOr<void> (and FutureOr<void>??) to this list.
Don't be alarmed, my motivation is not for users making FutureOr APIs, etc. My motivation is Future.catchError, see dart-lang/sdk#35825.
The onError parameter of Future<T>.catchError is typed as Function, because the acceptable signatures of that function cannot be expressed right now. onError can either be FutureOr<T> Function(dynamic) or FutureOr<T> Function(dynamic, StackTrace). In either case the return type is FutureOr<T>.
I think it makes sense to be able to write a Future<void>.catchError handler with return; statements (Flutter engine does it in a few places).
More generally, and out of correctness, it seems inconsistent that FutureOr<void> f() {} is legal, a function body that falls off the edge without returning a value, but FutureOr<void> f() { return; } is illegal.
More generally, and out of correctness, it seems inconsistent that FutureOr<void> f() {} is legal, a function body that falls off the edge without returning a value, but FutureOr<void> f() { return; } is illegal.
According to the current spec, only
void
,dynamic
andNull
allow forreturn;
. I'd like to addFutureOr<void>
(andFutureOr<void>?
?) to this list.Don't be alarmed, my motivation is not for users making FutureOr APIs, etc. My motivation is
Future.catchError
, see dart-lang/sdk#35825.The
onError
parameter ofFuture<T>.catchError
is typed asFunction
, because the acceptable signatures of that function cannot be expressed right now.onError
can either beFutureOr<T> Function(dynamic)
orFutureOr<T> Function(dynamic, StackTrace)
. In either case the return type isFutureOr<T>
.I think it makes sense to be able to write a
Future<void>.catchError
handler withreturn;
statements (Flutter engine does it in a few places).More generally, and out of correctness, it seems inconsistent that
FutureOr<void> f() {}
is legal, a function body that falls off the edge without returning a value, butFutureOr<void> f() { return; }
is illegal.Related issues: At first I thought this was an analyzer bug (dart-lang/sdk#44480); other
catchError
discussion at dart-lang/sdk#34144The text was updated successfully, but these errors were encountered: