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

Regression: use_build_context_synchronously false positives on certain conditionals #4753

Closed
mernen opened this issue Sep 19, 2023 · 3 comments
Assignees
Labels
false-positive P2 A bug or feature request we're likely to work on set-flutter Affects a rule in the recommended Flutter rule set

Comments

@mernen
Copy link

mernen commented Sep 19, 2023

Example:

import 'package:flutter/material.dart';

class TestState extends State {
  final _somethingElse = false;

  void testLeftHandMounted() async {
    await Future.value(0);
    if (!mounted || _somethingElse) return;

    Navigator.pop(context); // bogus use_build_context_synchronously (3.13 only)
  }

  void testRightHandMounted() async {
    await Future.value(0);
    if (_somethingElse || !mounted) return;

    Navigator.pop(context); // bogus use_build_context_synchronously (3.13, beta, master)
  }

  @override
  Widget build(BuildContext context) => const Placeholder();
}

The first test was fixed on unstable builds (still a regression on stable), but the second one remains:

Flutter testLeftHandMounted testRightHandMounted
3.7.12
3.10.6
stable (3.13.4)
beta (3.15.0-15.1.pre)
master

The specific version tested for master was Flutter engine 10c480310926d7e04a77ba8a04d321f9d225a545.

@github-actions github-actions bot added the set-flutter Affects a rule in the recommended Flutter rule set label Sep 19, 2023
@pq
Copy link
Member

pq commented Sep 19, 2023

@srawlins

@pq pq added the P2 A bug or feature request we're likely to work on label Sep 19, 2023
@srawlins
Copy link
Member

Thanks for the excellent bug report!

@srawlins srawlins self-assigned this Sep 20, 2023
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Sep 20, 2023
This PR fixes the case demonstrated in the new test, where
a mounted check occurs on the right side of an or-binary
expression.

Fixes dart-lang/linter#4753

Change-Id: I3c4ac8a42f7f87502fb217763506fa5294f6b017
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326864
Auto-Submit: Samuel Rawlins <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Phil Quitslund <[email protected]>
@srawlins
Copy link
Member

Fixed at HEAD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive P2 A bug or feature request we're likely to work on set-flutter Affects a rule in the recommended Flutter rule set
Projects
None yet
Development

No branches or pull requests

3 participants