Skip to content

Removes unnecessary boolean operations #9361

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void main() {

// Auto-consume must be true on iOS.
// To try without auto-consume on another platform, change `true` to `false` here.
// ignore: no_literal_bool_comparisons
final bool _kAutoConsume = Platform.isIOS || true;

const String _kConsumableId = 'consumable';
Expand Down
1 change: 1 addition & 0 deletions packages/rfw/test/argument_decoders_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

// This file is hand-formatted.
// ignore_for_file: no_literal_bool_comparisons

import 'dart:ui' as ui;

Expand Down
12 changes: 7 additions & 5 deletions packages/rfw/test/material_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: no_literal_bool_comparisons

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -245,7 +247,7 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/material_test.drawer.png'),
skip: !runGoldens,
skip: !runGoldens || true,
);
});

Expand Down Expand Up @@ -323,7 +325,7 @@ void main() {
find.byType(RemoteWidget),
matchesGoldenFile(
'goldens/material_test.button_bar_properties.overflow.png'),
skip: !runGoldens,
skip: !runGoldens || true,
);
});

Expand Down Expand Up @@ -450,7 +452,7 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/material_test.overflow_bar_properties.png'),
skip: !runGoldens,
skip: !runGoldens || true,
);

// Update the surface size for OverflowBar to overflow.
Expand Down Expand Up @@ -524,7 +526,7 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/material_test.ink_response_hover.png'),
skip: !runGoldens,
skip: !runGoldens || true,
);
expect(eventLog, contains('onHover {}'));

Expand All @@ -537,7 +539,7 @@ void main() {
await expectLater(
find.byType(RemoteWidget),
matchesGoldenFile('goldens/material_test.ink_response_tap.png'),
skip: !runGoldens,
skip: !runGoldens || true,
);
await gesture.up();
await tester.pump();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Future<bool> launch(
final bool isWebURL =
url != null && (url.scheme == 'http' || url.scheme == 'https');

if ((forceSafariVC ?? false || forceWebView) && !isWebURL) {
if ((forceSafariVC ?? forceWebView) && !isWebURL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have changed the behavior of this code; forceSafariVC = false and forceWebView = true now evaluates, incorrectly, to false.

I don't understand how this tripped the lint in the first place. What is wrong with using ?? <default value> with a nullable boolean? Is there a bug in the linter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as I can see. The precedence in the operators (as I tipped in the PR description) actually does this.

The first thing that will occur is false || forceWebView and only then forceSafariVC ?? expr.

https://github.com/dart-lang/sdk/blob/da5ae4786cc41812eee6f83ed1e9c5c05c15f387/pkg/_fe_analyzer_shared/lib/src/scanner/token.dart#L21-L22

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that's very unintuitive. That means that the code was unfortunately incorrect and we just hadn't noticed. Linter improvement to the rescue!

In that case the fix for the lint here is to add the parens to make the code work as intended, where forceSafariVC ?? false is one logical unit, and to add a test like this one for the broken case to make sure we don't regress it later.

throw PlatformException(
code: 'NOT_A_WEB_SCHEME',
message: 'To use webview or safariVC, you need to pass '
Expand Down