Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer reports a return-without-value in a FutureOr<void> function; does not report empty function #44480

Open
srawlins opened this issue Dec 15, 2020 · 5 comments
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) NNBD Issues related to NNBD Release P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@srawlins
Copy link
Member

See these two functions, each in null safe code:

import 'dart:async';

FutureOr<void> f1() {
  return; // error: return_without_value
}

FutureOr<void> f2() {} // clean

A bit odd. I assume the return_without_value report is erroneous.

@srawlins srawlins added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) NNBD Issues related to NNBD Release labels Dec 15, 2020
@srawlins
Copy link
Member Author

@scheglov if the analyzer should not be reporting that return statement in f1, I can fix in ReturnTypeVerifier; I'm poking around there now.

@eernstg
Copy link
Member

eernstg commented Dec 16, 2020

It is a bit odd, but it does follow the specification, here: Only void, dynamic and Null allow for return;. We have some null safety related updates about returns here, but the return; rule is unchanged.

So it's currently not a bug, it is working as intended. If you wish to make it a bug then it should be handled as a language proposal.

Note that the type FutureOr<void> is inherently questionable: FutureOr is an untagged union (like Future<void> | void), but the void type admits any object whatsoever, including futures. This means that there is no safe way to determine which case we have for a value of type FutureOr<void>: If it is not a future then it's the case void (so we should ignore and discard the value), but if it is a Future<T> for some T then it could be intended to be used as a future, or it could be intended as a void value that the caller should discard.

For anyone who wishes to make a distinction between a value of no interest and a future (so the future "may or may not be there"), the type Future<T>? is a much better match: It can be detected whether the given object is null or a future.

@srawlins
Copy link
Member Author

Thanks so much for the explanation, @eernstg !

@srawlins
Copy link
Member Author

I've filed dart-lang/language#1370

@srawlins srawlins added the contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) label May 20, 2022
@srawlins
Copy link
Member Author

Still not reported.

@srawlins srawlins added the analyzer-warning Issues with the analyzer's Warning codes label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) NNBD Issues related to NNBD Release P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants