-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stable][cfe] Allow void typed switch expression
Fixes #52234 Bug:#52191 Change-Id: I74d749115ec8cab0a89416ca905aa9c4e0d83ccc Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/299020 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303020 Commit-Queue: Leaf Petersen <leafp@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
- Loading branch information
1 parent
06b4ead
commit ea2a2b8
Showing
10 changed files
with
283 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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); | ||
} |
45 changes: 45 additions & 0 deletions
45
pkg/front_end/testcases/patterns/issue52191.dart.strong.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
static method printBugsSwitch(core::int n) → void | ||
return block { | ||
void #t1; | ||
final synthesized core::int #0#0 = n; | ||
#L1: | ||
{ | ||
{ | ||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("no bugs"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(#C2 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("one bug"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(true) { | ||
#t1 = core::print("${n} bugs"); | ||
break #L1; | ||
} | ||
} | ||
} | ||
} =>#t1; | ||
static method printBugsConditional(core::int n) → void | ||
return n =={core::num::==}{(core::Object) → core::bool} 0 ?{void} core::print("no bugs") : n =={core::num::==}{(core::Object) → core::bool} 1 ?{void} core::print("one bug") : core::print("${n} bugs"); | ||
static method main() → dynamic { | ||
self::printBugsSwitch(0); | ||
self::printBugsSwitch(1); | ||
self::printBugsSwitch(2); | ||
self::printBugsConditional(0); | ||
self::printBugsConditional(1); | ||
self::printBugsConditional(2); | ||
} | ||
|
||
constants { | ||
#C1 = 0 | ||
#C2 = 1 | ||
} |
45 changes: 45 additions & 0 deletions
45
pkg/front_end/testcases/patterns/issue52191.dart.strong.transformed.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
static method printBugsSwitch(core::int n) → void | ||
return block { | ||
void #t1; | ||
final synthesized core::int #0#0 = n; | ||
#L1: | ||
{ | ||
{ | ||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("no bugs"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(#C2 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("one bug"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(true) { | ||
#t1 = core::print("${n} bugs"); | ||
break #L1; | ||
} | ||
} | ||
} | ||
} =>#t1; | ||
static method printBugsConditional(core::int n) → void | ||
return n =={core::num::==}{(core::Object) → core::bool} 0 ?{void} core::print("no bugs") : n =={core::num::==}{(core::Object) → core::bool} 1 ?{void} core::print("one bug") : core::print("${n} bugs"); | ||
static method main() → dynamic { | ||
self::printBugsSwitch(0); | ||
self::printBugsSwitch(1); | ||
self::printBugsSwitch(2); | ||
self::printBugsConditional(0); | ||
self::printBugsConditional(1); | ||
self::printBugsConditional(2); | ||
} | ||
|
||
constants { | ||
#C1 = 0 | ||
#C2 = 1 | ||
} |
7 changes: 7 additions & 0 deletions
7
pkg/front_end/testcases/patterns/issue52191.dart.textual_outline.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
void printBugsSwitch(int n) => switch (n) {}; | ||
void printBugsConditional(int n) => n == 0 | ||
? print('no bugs') | ||
: n == 1 | ||
? print('one bug') | ||
: print('$n bugs'); | ||
main() {} |
7 changes: 7 additions & 0 deletions
7
pkg/front_end/testcases/patterns/issue52191.dart.textual_outline_modelled.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
switch (n) {} | ||
void printBugsSwitch(int n) => | ||
---- unknown chunk starts ---- | ||
; | ||
---- unknown chunk ends ---- | ||
main() {} | ||
void printBugsConditional(int n) => n == 0 ? print('no bugs') : n == 1 ? print('one bug') : print('$n bugs'); |
47 changes: 47 additions & 0 deletions
47
pkg/front_end/testcases/patterns/issue52191.dart.weak.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "dart:_internal" as _in; | ||
|
||
static method printBugsSwitch(core::int n) → void | ||
return block { | ||
void #t1; | ||
final synthesized core::int #0#0 = n; | ||
#L1: | ||
{ | ||
{ | ||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("no bugs"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(#C2 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("one bug"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(true) { | ||
#t1 = core::print("${n} bugs"); | ||
break #L1; | ||
} | ||
} | ||
throw new _in::ReachabilityError::•("`null` encountered as case in a switch expression with a non-nullable type."); | ||
} | ||
} =>#t1; | ||
static method printBugsConditional(core::int n) → void | ||
return n =={core::num::==}{(core::Object) → core::bool} 0 ?{void} core::print("no bugs") : n =={core::num::==}{(core::Object) → core::bool} 1 ?{void} core::print("one bug") : core::print("${n} bugs"); | ||
static method main() → dynamic { | ||
self::printBugsSwitch(0); | ||
self::printBugsSwitch(1); | ||
self::printBugsSwitch(2); | ||
self::printBugsConditional(0); | ||
self::printBugsConditional(1); | ||
self::printBugsConditional(2); | ||
} | ||
|
||
constants { | ||
#C1 = 0 | ||
#C2 = 1 | ||
} |
47 changes: 47 additions & 0 deletions
47
pkg/front_end/testcases/patterns/issue52191.dart.weak.modular.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "dart:_internal" as _in; | ||
|
||
static method printBugsSwitch(core::int n) → void | ||
return block { | ||
void #t1; | ||
final synthesized core::int #0#0 = n; | ||
#L1: | ||
{ | ||
{ | ||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("no bugs"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(#C2 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("one bug"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(true) { | ||
#t1 = core::print("${n} bugs"); | ||
break #L1; | ||
} | ||
} | ||
throw new _in::ReachabilityError::•("`null` encountered as case in a switch expression with a non-nullable type."); | ||
} | ||
} =>#t1; | ||
static method printBugsConditional(core::int n) → void | ||
return n =={core::num::==}{(core::Object) → core::bool} 0 ?{void} core::print("no bugs") : n =={core::num::==}{(core::Object) → core::bool} 1 ?{void} core::print("one bug") : core::print("${n} bugs"); | ||
static method main() → dynamic { | ||
self::printBugsSwitch(0); | ||
self::printBugsSwitch(1); | ||
self::printBugsSwitch(2); | ||
self::printBugsConditional(0); | ||
self::printBugsConditional(1); | ||
self::printBugsConditional(2); | ||
} | ||
|
||
constants { | ||
#C1 = 0 | ||
#C2 = 1 | ||
} |
10 changes: 10 additions & 0 deletions
10
pkg/front_end/testcases/patterns/issue52191.dart.weak.outline.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
static method printBugsSwitch(core::int n) → void | ||
; | ||
static method printBugsConditional(core::int n) → void | ||
; | ||
static method main() → dynamic | ||
; |
47 changes: 47 additions & 0 deletions
47
pkg/front_end/testcases/patterns/issue52191.dart.weak.transformed.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "dart:_internal" as _in; | ||
|
||
static method printBugsSwitch(core::int n) → void | ||
return block { | ||
void #t1; | ||
final synthesized core::int #0#0 = n; | ||
#L1: | ||
{ | ||
{ | ||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("no bugs"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(#C2 =={core::num::==}{(core::Object) → core::bool} #0#0) { | ||
#t1 = core::print("one bug"); | ||
break #L1; | ||
} | ||
} | ||
{ | ||
if(true) { | ||
#t1 = core::print("${n} bugs"); | ||
break #L1; | ||
} | ||
} | ||
throw new _in::ReachabilityError::•("`null` encountered as case in a switch expression with a non-nullable type."); | ||
} | ||
} =>#t1; | ||
static method printBugsConditional(core::int n) → void | ||
return n =={core::num::==}{(core::Object) → core::bool} 0 ?{void} core::print("no bugs") : n =={core::num::==}{(core::Object) → core::bool} 1 ?{void} core::print("one bug") : core::print("${n} bugs"); | ||
static method main() → dynamic { | ||
self::printBugsSwitch(0); | ||
self::printBugsSwitch(1); | ||
self::printBugsSwitch(2); | ||
self::printBugsConditional(0); | ||
self::printBugsConditional(1); | ||
self::printBugsConditional(2); | ||
} | ||
|
||
constants { | ||
#C1 = 0 | ||
#C2 = 1 | ||
} |