[analyzer] Adds warning for missng await in return in try block
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Once I get your approval, I (or you) will add the missing reviewers for the landing changes here.
Can I get a pre-review before landing https://github.com/flutter/flutter/pull/183466, please? Thanks a lot!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
And just to note around here. This unblocks https://dart-review.googlesource.com/c/sdk/+/477660.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
final TypeSystem typeSystem;Each of these fields can be private.
if (returnType is! TypeImpl) return;Why is this check here? `TypeSystem.futureValueType` accepts a DartType.
if (typeSystem is TypeSystemImpl &&Why do we need TypeSystemImpl? Both `isAssignableTo` and `futureValueType` are available on TypeSystem.
bool get withinTryBlock {This name is a little strange; it sounds like something that returns a ReturnStatement within a try block.
How about 'isWithinTryBlock`.
reportAtToken: _reportUnawaitedReturnInTryBlock,Why do we wrap up this instance method and send it to `AsyncReturnVisitor`? I think it would be much simpler to just send the `DiagnosticReporter`.
`async` function and within a `try` block without using `await`.Maybe more readable by flipping these two clauses:
.. is returned within a `try` block, in an `async` function, without using `await`.
I'm also not sure "using await" is the best verbiage, but maybe it's fine. Otherwise we might say something like "without awaiting the returned Future."
class UnawaitedReturnInTryBlockTest extends PubPackageResolutionTest {Great test coverage. I have only one more I can think of:
How about an `async*` generator? Return statements are not legal in `async*`, but I guess we should not compound the confusion, and we should not report this warning in this case.
Future<void> test_insideClosure() async {I think we need one more "within closure" test for a case I'm thinking of:
```
void foo() {
try {
var x = () async => return Future.value(null);
} catch (_) {}
}
```
In this case, the return statement is illegal, but I want to make sure we don't also report the lint. So if we encounter an ExpressionFunctionBody (I think), then we also want to stop searching up the syntax tree for a try-statement.
Future<void> test_sync() async {What does "sync" mean here?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
Each of these fields can be private.
Thanks!
Why is this check here? `TypeSystem.futureValueType` accepts a DartType.
Recent change I opened because of the previous CL: https://github.com/dart-lang/sdk/issues/62583.
Thanks for noting!
Why do we need TypeSystemImpl? Both `isAssignableTo` and `futureValueType` are available on TypeSystem.
We needed them because of the previous comment: `TypeSystem.futureValueType` wasn't a thing yet.
This name is a little strange; it sounds like something that returns a ReturnStatement within a try block.
How about 'isWithinTryBlock`.
Yes, thanks!
reportAtToken: _reportUnawaitedReturnInTryBlock,Why do we wrap up this instance method and send it to `AsyncReturnVisitor`? I think it would be much simpler to just send the `DiagnosticReporter`.
Because we either do this or we also send the exact diagnostic and handle it differently here and over at the lint CL https://dart-review.googlesource.com/c/sdk/+/477660. I think this is easier to reason about for both cases, but if you disagree, I can change it.
`async` function and within a `try` block without using `await`.Maybe more readable by flipping these two clauses:
.. is returned within a `try` block, in an `async` function, without using `await`.
I'm also not sure "using await" is the best verbiage, but maybe it's fine. Otherwise we might say something like "without awaiting the returned Future."
Thanks!
class UnawaitedReturnInTryBlockTest extends PubPackageResolutionTest {Great test coverage. I have only one more I can think of:
How about an `async*` generator? Return statements are not legal in `async*`, but I guess we should not compound the confusion, and we should not report this warning in this case.
Thanks!
I think we need one more "within closure" test for a case I'm thinking of:
```
void foo() {
try {
var x = () async => return Future.value(null);
} catch (_) {}
}
```In this case, the return statement is illegal, but I want to make sure we don't also report the lint. So if we encounter an ExpressionFunctionBody (I think), then we also want to stop searching up the syntax tree for a try-statement.
Great case!
What does "sync" mean here?
I'll rename it. Since the return value of the `async` is not a `Future`, the internal completer handles it like a `sync` complete.
The test is better if named as `nonFuture`.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
reportAtToken: _reportUnawaitedReturnInTryBlock,Felipe MorschelWhy do we wrap up this instance method and send it to `AsyncReturnVisitor`? I think it would be much simpler to just send the `DiagnosticReporter`.
Because we either do this or we also send the exact diagnostic and handle it differently here and over at the lint CL https://dart-review.googlesource.com/c/sdk/+/477660. I think this is easier to reason about for both cases, but if you disagree, I can change it.
Ah of course, because of the lint rule. That makes sense.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
@sche...@google.com, could you please take a look at this?
I'd like to land this as soon as the Flutter PR (https://github.com/flutter/flutter/pull/183466) lands, so we can stop delaying this warning to avoid the bug explained in the issue.
Thanks a lot!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |