-
Notifications
You must be signed in to change notification settings - Fork 29.8k
if chains → switch expressions
#147793
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
if chains → switch expressions
#147793
Conversation
victorsanni
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM! I just some small questions that I wasn't too sure about.
| next = Brightness.light; | ||
| } | ||
| final Brightness next = switch (current) { | ||
| Brightness.light || null => Brightness.dark, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding of the if statement is that if and only if current == Brightness.light should next = Brightness.dark, otherwise (including the null case) next = Brightness.light. Is this change intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thank you!
The || null should go next to Brightness.dark.
| return switch (filter?.deviceConnectionInterface) { | ||
| DeviceConnectionInterface.attached => attachedDevices, | ||
| DeviceConnectionInterface.wireless => wirelessDevices, | ||
| null => attachedDevices + wirelessDevices, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little curious here as to why null is used instead of an arbitrary _ as in (almost) everywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum, bool, and sealed classes are exhaustive—Dart is able to understand when all cases have been covered.
A wildcard pattern _ in an enum switch expression (or default in a switch statement) goes against the style guideline that this pull request was named after.
I made this mistake during my first switch expressions pull request, but never again. 🙂
|
Merging manually, since |
flutter/flutter@2bfb1b0...2aa05c1 2024-05-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from fad88cb16d03 to 558a81dd8b08 (3 revisions) (flutter/flutter#148163) 2024-05-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from ba8e0d3e2f23 to fad88cb16d03 (9 revisions) (flutter/flutter#148156) 2024-05-11 32538273+ValentinVignal@users.noreply.github.com Add test for scaffold.1.dart (flutter/flutter#147966) 2024-05-10 tessertaha@gmail.com Fix `MaterialStateBorderSide` lerp in the `Checkbox` and chips (flutter/flutter#148124) 2024-05-10 jmccandless@google.com Docs on TextField disposed by a scrollable (flutter/flutter#148149) 2024-05-10 engine-flutter-autoroll@skia.org Roll Flutter Engine from d4f705ccb695 to ba8e0d3e2f23 (8 revisions) (flutter/flutter#148147) 2024-05-10 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#148148) 2024-05-10 32538273+ValentinVignal@users.noreply.github.com Add `clipBehavior` to `DialogTheme` (flutter/flutter#147635) 2024-05-10 31859944+LongCatIsLooong@users.noreply.github.com bump cupertino_icons to 1.08 (flutter/flutter#146806) 2024-05-10 sokolovskyi.konstantin@gmail.com Add test for animated_size.0.dart API example. (flutter/flutter#147828) 2024-05-10 120297255+PurplePolyhedron@users.noreply.github.com Fix `DropdownMenu` keyboard navigation (flutter/flutter#147294) 2024-05-10 sokolovskyi.konstantin@gmail.com Add test for draggable.0.dart API example. (flutter/flutter#147941) 2024-05-10 magder@google.com Update TESTOWNERS (flutter/flutter#148108) 2024-05-10 sokolovskyi.konstantin@gmail.com Add tests for stream_builder.0.dart API example. (flutter/flutter#147832) 2024-05-10 engine-flutter-autoroll@skia.org Roll Flutter Engine from 1ccd0c308b3a to d4f705ccb695 (2 revisions) (flutter/flutter#148142) 2024-05-10 engine-flutter-autoroll@skia.org Roll Packages from 8de142d to 6c4482a (8 revisions) (flutter/flutter#148079) 2024-05-10 engine-flutter-autoroll@skia.org Roll Flutter Engine from c0917b14fc36 to 1ccd0c308b3a (10 revisions) (flutter/flutter#148137) 2024-05-10 nate.w5687@gmail.com `if` chains � `switch` expressions (flutter/flutter#147793) 2024-05-10 49699333+dependabot[bot]@users.noreply.github.com Bump ossf/scorecard-action from 2.3.1 to 2.3.3 (flutter/flutter#148091) 2024-05-10 31859944+LongCatIsLooong@users.noreply.github.com Reland "Implement computeDryBaseline for `RenderWrap` (#146260)" (flutter/flutter#148086) 2024-05-10 magder@google.com Update dependabot reviewers (flutter/flutter#148101) 2024-05-10 engine-flutter-autoroll@skia.org Roll Flutter Engine from 6e722ae213bd to c0917b14fc36 (1 revision) (flutter/flutter#148084) 2024-05-09 christopherfujino@gmail.com Don't pin package:macros (flutter/flutter#148087) 2024-05-09 ian@hixie.ch Remove hidden dependencies on the default LocalPlatform (flutter/flutter#147342) 2024-05-09 nate.w5687@gmail.com Getting rid of containers (flutter/flutter#147432) 2024-05-09 engine-flutter-autoroll@skia.org Roll Flutter Engine from c0fd3386d018 to 6e722ae213bd (2 revisions) (flutter/flutter#148070) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC bmparr@google.com,rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
I did a goof a while back:  Now that [the bug is fixed](e9d4035), I think we're good to re-implement the if-chains cleanup! Related: - #147793 - #148556 - #148548
flutter/flutter@2bfb1b0...2aa05c1 2024-05-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from fad88cb16d03 to 558a81dd8b08 (3 revisions) (flutter/flutter#148163) 2024-05-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from ba8e0d3e2f23 to fad88cb16d03 (9 revisions) (flutter/flutter#148156) 2024-05-11 32538273+ValentinVignal@users.noreply.github.com Add test for scaffold.1.dart (flutter/flutter#147966) 2024-05-10 tessertaha@gmail.com Fix `MaterialStateBorderSide` lerp in the `Checkbox` and chips (flutter/flutter#148124) 2024-05-10 jmccandless@google.com Docs on TextField disposed by a scrollable (flutter/flutter#148149) 2024-05-10 engine-flutter-autoroll@skia.org Roll Flutter Engine from d4f705ccb695 to ba8e0d3e2f23 (8 revisions) (flutter/flutter#148147) 2024-05-10 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#148148) 2024-05-10 32538273+ValentinVignal@users.noreply.github.com Add `clipBehavior` to `DialogTheme` (flutter/flutter#147635) 2024-05-10 31859944+LongCatIsLooong@users.noreply.github.com bump cupertino_icons to 1.08 (flutter/flutter#146806) 2024-05-10 sokolovskyi.konstantin@gmail.com Add test for animated_size.0.dart API example. (flutter/flutter#147828) 2024-05-10 120297255+PurplePolyhedron@users.noreply.github.com Fix `DropdownMenu` keyboard navigation (flutter/flutter#147294) 2024-05-10 sokolovskyi.konstantin@gmail.com Add test for draggable.0.dart API example. (flutter/flutter#147941) 2024-05-10 magder@google.com Update TESTOWNERS (flutter/flutter#148108) 2024-05-10 sokolovskyi.konstantin@gmail.com Add tests for stream_builder.0.dart API example. (flutter/flutter#147832) 2024-05-10 engine-flutter-autoroll@skia.org Roll Flutter Engine from 1ccd0c308b3a to d4f705ccb695 (2 revisions) (flutter/flutter#148142) 2024-05-10 engine-flutter-autoroll@skia.org Roll Packages from 8de142d to 6c4482a (8 revisions) (flutter/flutter#148079) 2024-05-10 engine-flutter-autoroll@skia.org Roll Flutter Engine from c0917b14fc36 to 1ccd0c308b3a (10 revisions) (flutter/flutter#148137) 2024-05-10 nate.w5687@gmail.com `if` chains � `switch` expressions (flutter/flutter#147793) 2024-05-10 49699333+dependabot[bot]@users.noreply.github.com Bump ossf/scorecard-action from 2.3.1 to 2.3.3 (flutter/flutter#148091) 2024-05-10 31859944+LongCatIsLooong@users.noreply.github.com Reland "Implement computeDryBaseline for `RenderWrap` (#146260)" (flutter/flutter#148086) 2024-05-10 magder@google.com Update dependabot reviewers (flutter/flutter#148101) 2024-05-10 engine-flutter-autoroll@skia.org Roll Flutter Engine from 6e722ae213bd to c0917b14fc36 (1 revision) (flutter/flutter#148084) 2024-05-09 christopherfujino@gmail.com Don't pin package:macros (flutter/flutter#148087) 2024-05-09 ian@hixie.ch Remove hidden dependencies on the default LocalPlatform (flutter/flutter#147342) 2024-05-09 nate.w5687@gmail.com Getting rid of containers (flutter/flutter#147432) 2024-05-09 engine-flutter-autoroll@skia.org Roll Flutter Engine from c0fd3386d018 to 6e722ae213bd (2 revisions) (flutter/flutter#148070) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC bmparr@google.com,rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Previous "if-chains" pull requests:
ifchains intoswitchstatements #144905ifchains into shorterswitchstatements #144977ifchain refactoring #145194flutter/lib/src/: refactoring if-chains into switch expressions #146293flutter/lib/src/: refactoring if-chains into switch expressions #147472I think this one should be enough to wrap things up!
fixes #144903