Skip to content

BuildContext across async gaps false positive for null-aware access + null operator #59655

@vendelin8

Description

@vendelin8

Describe the issue
Lint error use_build_context_synchronously when it was already checked

To Reproduce

final GlobalKey<NavigatorState> navKey = GlobalKey<NavigatorState>();

Future<void> newPhoto() async {
  await Future.delayed(const Duration(seconds: 1));
  final context = navKey.currentContext;
  if (!(context?.mounted ?? false)) {
    return;
  }
  Navigator.of(context!).pop(); // <- LINT ERROR HERE 
}

In an updated repo for this bug: https://github.com/vendelin8/dart-lintbug

Expected behavior
No lint infos, because mounted was already checked previously.

Additional context

dart --version
Dart SDK version: 3.5.4 (stable) (Wed Oct 16 16:18:51 2024 +0000) on "linux_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-set-fluttertype-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