Closed
Description
Right now, void foo() => bar()
is allowed if bar()
returns void
or dynamic
, and produces an error if it has any other return type. This makes sense on the surface, but it has pretty negative consequences. In particular, it means that it's not safe for an API to add a return type where none previously existed. This is a common refactor that would otherwise be totally backwards-compatible.
I can see three solutions to this problem:
- Eliminate the error if
bar()
has a return type. If it's valuable information, it could be downgraded to a warning or a hint. - Add a warning or error when using
=>
in a void context, so that thevoid foo() => bar()
pattern doesn't occur. - Keep the behavior as-is and forbid APIs from adding return types without major version increments.
I strongly prefer option 1, but I'd still choose option 2 over option 3. Under option 3 (the current state of the world), it's likely that API designers won't consider this edge case and will continue to add return types to their void methods, thus potentially breaking downstream users.