Files
sdk/pkg/front_end/testcases/patterns/issue52191.dart
T
Johnni Winther 88721baf2b [cfe] Allow void typed switch expression
This allows void typed switch expressions by allowed void typed
expressions in all subexpressions inferred through the shared type
analysis.

This might lead to allowing void in intended places but the current
approach employed by the CFE doesn't really scale so we need to revisit
it anyway.

In response to https://github.com/dart-lang/sdk/issues/52191

Change-Id: Iee53670d3c316764cfc1309dc76cf37bb3b03629
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299020
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-04-28 06:50:51 +00:00

26 lines
650 B
Dart

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
void printBugsSwitch(int n) => switch (n) {
0 => print('no bugs'),
1 => print('one bug'),
_ => print('$n bugs'),
};
void printBugsConditional(int n) => n == 0
? print('no bugs')
: n == 1
? print('one bug')
: print('$n bugs');
main() {
printBugsSwitch(0);
printBugsSwitch(1);
printBugsSwitch(2);
printBugsConditional(0);
printBugsConditional(1);
printBugsConditional(2);
}