[L] Change in dart/sdk[main]: [analyzer] Adds warning for missng await in return in try block

0 views
Skip to first unread message

Felipe Morschel (Gerrit)

unread,
Mar 10, 2026, 6:20:04 PMMar 10
to dart-analys...@google.com, dart-fe-te...@google.com, rev...@dartlang.org

Felipe Morschel has uploaded the change for review

Commit message

[analyzer] Adds warning for missng await in return in try block
Change-Id: Ic152d89e94739aefd79f71972691722d4cdd0946

Change information

Files:
  • M pkg/analysis_server/lib/src/lsp/handlers/commands/fix_all_in_workspace.dart
  • M pkg/analysis_server/lib/src/services/correction/dart/add_await.dart
  • M pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
  • M pkg/analysis_server/lib/src/services/correction/fix_internal.dart
  • M pkg/analysis_server/lib/src/utilities/profiling.dart
  • M pkg/analysis_server/test/src/services/correction/fix/add_await_test.dart
  • M pkg/analyzer/lib/src/diagnostic/diagnostic.g.dart
  • M pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart
  • A pkg/analyzer/lib/src/error/async_return_visitor.dart
  • M pkg/analyzer/lib/src/generated/error_verifier.dart
  • M pkg/analyzer/messages.yaml
  • M pkg/analyzer/test/src/diagnostics/test_all.dart
  • A pkg/analyzer/test/src/diagnostics/unawaited_return_in_try_block_test.dart
  • M pkg/dds/lib/src/dap/protocol_converter.dart
  • M pkg/front_end/lib/src/base/crash.dart
  • M pkg/test_runner/lib/src/browser_controller.dart
Change size: L
Delta: 16 files changed, 488 insertions(+), 20 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Ic152d89e94739aefd79f71972691722d4cdd0946
Gerrit-Change-Number: 486920
Gerrit-PatchSet: 1
Gerrit-Owner: Felipe Morschel <g...@fmorschel.dev>
Gerrit-Reviewer: Felipe Morschel <g...@fmorschel.dev>
unsatisfied_requirement
open
diffy

Felipe Morschel (Gerrit)

unread,
Mar 10, 2026, 6:25:08 PMMar 10
to Konstantin Shcheglov, Samuel Rawlins, dart-analys...@google.com, dart-fe-te...@google.com, rev...@dartlang.org
Attention needed from Konstantin Shcheglov and Samuel Rawlins

Felipe Morschel added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Felipe Morschel . resolved

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!

CC @sche...@google.com

Open in Gerrit

Related details

Attention is currently required from:
  • Konstantin Shcheglov
  • Samuel Rawlins
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Ic152d89e94739aefd79f71972691722d4cdd0946
Gerrit-Change-Number: 486920
Gerrit-PatchSet: 1
Gerrit-Owner: Felipe Morschel <g...@fmorschel.dev>
Gerrit-Reviewer: Felipe Morschel <g...@fmorschel.dev>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
Gerrit-Attention: Samuel Rawlins <sraw...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Comment-Date: Tue, 10 Mar 2026 22:25:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Felipe Morschel (Gerrit)

unread,
Mar 10, 2026, 6:44:21 PMMar 10
to Konstantin Shcheglov, Samuel Rawlins, dart-analys...@google.com, dart-fe-te...@google.com, rev...@dartlang.org
Attention needed from Konstantin Shcheglov and Samuel Rawlins

Felipe Morschel voted and added 1 comment

Votes added by Felipe Morschel

Auto-Submit+1

1 comment

Patchset-level comments
File-level comment, Patchset 1:
Felipe Morschel . resolved

And just to note around here. This unblocks https://dart-review.googlesource.com/c/sdk/+/477660.

Open in Gerrit

Related details

Attention is currently required from:
  • Konstantin Shcheglov
  • Samuel Rawlins
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Ic152d89e94739aefd79f71972691722d4cdd0946
Gerrit-Change-Number: 486920
Gerrit-PatchSet: 1
Gerrit-Owner: Felipe Morschel <g...@fmorschel.dev>
Gerrit-Reviewer: Felipe Morschel <g...@fmorschel.dev>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
Gerrit-Attention: Samuel Rawlins <sraw...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Comment-Date: Tue, 10 Mar 2026 22:44:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
unsatisfied_requirement
open
diffy

Samuel Rawlins (Gerrit)

unread,
Mar 11, 2026, 5:06:35 PMMar 11
to Felipe Morschel, Konstantin Shcheglov, dart-analys...@google.com, dart-fe-te...@google.com, rev...@dartlang.org
Attention needed from Felipe Morschel and Konstantin Shcheglov

Samuel Rawlins voted and added 9 comments

Votes added by Samuel Rawlins

Code-Review+1

9 comments

File pkg/analyzer/lib/src/error/async_return_visitor.dart
Line 15, Patchset 2 (Latest): final TypeSystem typeSystem;
Samuel Rawlins . unresolved

Each of these fields can be private.

Line 55, Patchset 2 (Latest): if (returnType is! TypeImpl) return;
Samuel Rawlins . unresolved

Why is this check here? `TypeSystem.futureValueType` accepts a DartType.

Line 57, Patchset 2 (Latest): if (typeSystem is TypeSystemImpl &&
Samuel Rawlins . unresolved

Why do we need TypeSystemImpl? Both `isAssignableTo` and `futureValueType` are available on TypeSystem.

Line 69, Patchset 2 (Latest): bool get withinTryBlock {
Samuel Rawlins . unresolved

This name is a little strange; it sounds like something that returns a ReturnStatement within a try block.

How about 'isWithinTryBlock`.

File pkg/analyzer/lib/src/generated/error_verifier.dart
Line 334, Patchset 2 (Latest): reportAtToken: _reportUnawaitedReturnInTryBlock,
Samuel Rawlins . unresolved

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`.

File pkg/analyzer/messages.yaml
Line 24314, Patchset 2 (Latest): `async` function and within a `try` block without using `await`.
Samuel Rawlins . unresolved

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."

File pkg/analyzer/test/src/diagnostics/unawaited_return_in_try_block_test.dart
Line 17, Patchset 2 (Latest):class UnawaitedReturnInTryBlockTest extends PubPackageResolutionTest {
Samuel Rawlins . unresolved

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.

Line 115, Patchset 2 (Latest): Future<void> test_insideClosure() async {
Samuel Rawlins . unresolved

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.

Line 149, Patchset 2 (Latest): Future<void> test_sync() async {
Samuel Rawlins . unresolved

What does "sync" mean here?

Open in Gerrit

Related details

Attention is currently required from:
  • Felipe Morschel
  • Konstantin Shcheglov
Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: Ic152d89e94739aefd79f71972691722d4cdd0946
    Gerrit-Change-Number: 486920
    Gerrit-PatchSet: 2
    Gerrit-Owner: Felipe Morschel <g...@fmorschel.dev>
    Gerrit-Reviewer: Felipe Morschel <g...@fmorschel.dev>
    Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
    Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
    Gerrit-Attention: Felipe Morschel <g...@fmorschel.dev>
    Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
    Gerrit-Comment-Date: Wed, 11 Mar 2026 21:06:31 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Felipe Morschel (Gerrit)

    unread,
    Mar 12, 2026, 8:49:05 AMMar 12
    to Commit Queue, Samuel Rawlins, Konstantin Shcheglov, dart-analys...@google.com, dart-fe-te...@google.com, rev...@dartlang.org
    Attention needed from Konstantin Shcheglov and Samuel Rawlins

    Felipe Morschel voted and added 9 comments

    Votes added by Felipe Morschel

    Auto-Submit+1

    9 comments

    File pkg/analyzer/lib/src/error/async_return_visitor.dart
    Line 15, Patchset 2: final TypeSystem typeSystem;
    Samuel Rawlins . resolved

    Each of these fields can be private.

    Felipe Morschel

    Thanks!

    Line 55, Patchset 2: if (returnType is! TypeImpl) return;
    Samuel Rawlins . resolved

    Why is this check here? `TypeSystem.futureValueType` accepts a DartType.

    Felipe Morschel

    Recent change I opened because of the previous CL: https://github.com/dart-lang/sdk/issues/62583.

    Thanks for noting!

    Line 57, Patchset 2: if (typeSystem is TypeSystemImpl &&
    Samuel Rawlins . resolved

    Why do we need TypeSystemImpl? Both `isAssignableTo` and `futureValueType` are available on TypeSystem.

    Felipe Morschel

    We needed them because of the previous comment: `TypeSystem.futureValueType` wasn't a thing yet.

    Line 69, Patchset 2: bool get withinTryBlock {
    Samuel Rawlins . resolved

    This name is a little strange; it sounds like something that returns a ReturnStatement within a try block.

    How about 'isWithinTryBlock`.

    Felipe Morschel

    Yes, thanks!

    File pkg/analyzer/lib/src/generated/error_verifier.dart
    Line 334, Patchset 2: reportAtToken: _reportUnawaitedReturnInTryBlock,
    Samuel Rawlins . unresolved

    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`.

    Felipe Morschel

    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.

    File pkg/analyzer/messages.yaml
    Line 24314, Patchset 2: `async` function and within a `try` block without using `await`.
    Samuel Rawlins . resolved

    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."

    Felipe Morschel

    Thanks!

    File pkg/analyzer/test/src/diagnostics/unawaited_return_in_try_block_test.dart
    Line 17, Patchset 2:class UnawaitedReturnInTryBlockTest extends PubPackageResolutionTest {
    Samuel Rawlins . resolved

    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.

    Felipe Morschel

    Thanks!

    Line 115, Patchset 2: Future<void> test_insideClosure() async {
    Samuel Rawlins . resolved

    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.

    Felipe Morschel

    Great case!

    Line 149, Patchset 2: Future<void> test_sync() async {
    Samuel Rawlins . resolved

    What does "sync" mean here?

    Felipe Morschel

    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`.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Konstantin Shcheglov
    • Samuel Rawlins
    Submit Requirements:
      • requirement is not satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: sdk
      Gerrit-Branch: main
      Gerrit-Change-Id: Ic152d89e94739aefd79f71972691722d4cdd0946
      Gerrit-Change-Number: 486920
      Gerrit-PatchSet: 2
      Gerrit-Owner: Felipe Morschel <g...@fmorschel.dev>
      Gerrit-Reviewer: Felipe Morschel <g...@fmorschel.dev>
      Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
      Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
      Gerrit-Attention: Samuel Rawlins <sraw...@google.com>
      Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
      Gerrit-Comment-Date: Thu, 12 Mar 2026 12:49:02 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Samuel Rawlins <sraw...@google.com>
      unsatisfied_requirement
      open
      diffy

      Samuel Rawlins (Gerrit)

      unread,
      Mar 12, 2026, 9:53:33 AMMar 12
      to Felipe Morschel, Commit Queue, Konstantin Shcheglov, dart-analys...@google.com, dart-fe-te...@google.com, rev...@dartlang.org
      Attention needed from Felipe Morschel and Konstantin Shcheglov

      Samuel Rawlins voted and added 1 comment

      Votes added by Samuel Rawlins

      Code-Review+1

      1 comment

      File pkg/analyzer/lib/src/generated/error_verifier.dart
      Line 334, Patchset 2: reportAtToken: _reportUnawaitedReturnInTryBlock,
      Samuel Rawlins . resolved

      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`.

      Felipe Morschel

      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.

      Samuel Rawlins

      Ah of course, because of the lint rule. That makes sense.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Felipe Morschel
      • Konstantin Shcheglov
      Submit Requirements:
        • requirement is not satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: sdk
        Gerrit-Branch: main
        Gerrit-Change-Id: Ic152d89e94739aefd79f71972691722d4cdd0946
        Gerrit-Change-Number: 486920
        Gerrit-PatchSet: 3
        Gerrit-Owner: Felipe Morschel <g...@fmorschel.dev>
        Gerrit-Reviewer: Felipe Morschel <g...@fmorschel.dev>
        Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
        Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
        Gerrit-Attention: Felipe Morschel <g...@fmorschel.dev>
        Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
        Gerrit-Comment-Date: Thu, 12 Mar 2026 13:53:29 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        Comment-In-Reply-To: Felipe Morschel <g...@fmorschel.dev>
        Comment-In-Reply-To: Samuel Rawlins <sraw...@google.com>
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Felipe Morschel (Gerrit)

        unread,
        Mar 13, 2026, 11:44:27 AMMar 13
        to Samuel Rawlins, Commit Queue, Konstantin Shcheglov, dart-analys...@google.com, dart-fe-te...@google.com, rev...@dartlang.org
        Attention needed from Konstantin Shcheglov

        Felipe Morschel voted and added 1 comment

        Votes added by Felipe Morschel

        Auto-Submit+1

        1 comment

        Patchset-level comments
        File-level comment, Patchset 3 (Latest):
        Felipe Morschel . unresolved

        @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!

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Konstantin Shcheglov
        Submit Requirements:
        • requirement is not satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: sdk
        Gerrit-Branch: main
        Gerrit-Change-Id: Ic152d89e94739aefd79f71972691722d4cdd0946
        Gerrit-Change-Number: 486920
        Gerrit-PatchSet: 3
        Gerrit-Owner: Felipe Morschel <g...@fmorschel.dev>
        Gerrit-Reviewer: Felipe Morschel <g...@fmorschel.dev>
        Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
        Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
        Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
        Gerrit-Comment-Date: Fri, 13 Mar 2026 15:44:24 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy
        Reply all
        Reply to author
        Forward
        0 new messages