Skip to content

Analysis of void return type with arrow causes bad API restrictions #28763

Closed
@nex3

Description

@nex3

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:

  1. Eliminate the error if bar() has a return type. If it's valuable information, it could be downgraded to a warning or a hint.
  2. Add a warning or error when using => in a void context, so that the void foo() => bar() pattern doesn't occur.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onclosed-obsoleteClosed as the reported issue is no longer relevantlegacy-area-analyzerUse area-devexp instead.status-blockedBlocked from making progress by another (referenced) issuetype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions