mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:19:48 +00:00
[cfe] Handle continue to default case
Closes #51553 Change-Id: I1a1174e786eeb79db42e6da940a03cf05c2dabe5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286823 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
874e7ee056
commit
6f752165ea
|
@ -8375,14 +8375,17 @@ class InferenceVisitorImpl extends InferenceVisitorBase
|
|||
Map<String, List<VariableDeclaration>> declaredVariablesByName = {};
|
||||
|
||||
bool hasContinue = false;
|
||||
for (PatternSwitchCase switchCase in node.cases) {
|
||||
if (switchCase.labelUsers.isNotEmpty) {
|
||||
hasContinue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
List<List<DelayedExpression>> matchingExpressions =
|
||||
new List.generate(node.cases.length, (int caseIndex) {
|
||||
PatternSwitchCase switchCase = node.cases[caseIndex];
|
||||
return new List.generate(switchCase.patternGuards.length,
|
||||
(int headIndex) {
|
||||
if (switchCase.labelUsers.isNotEmpty) {
|
||||
hasContinue = true;
|
||||
}
|
||||
Pattern pattern = switchCase.patternGuards[headIndex].pattern;
|
||||
DelayedExpression matchingExpression =
|
||||
matchingExpressionVisitor.visitPattern(
|
||||
|
|
12
pkg/front_end/testcases/patterns/issue51553.dart
Normal file
12
pkg/front_end/testcases/patterns/issue51553.dart
Normal file
|
@ -0,0 +1,12 @@
|
|||
// 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.
|
||||
|
||||
main() {
|
||||
switch (0) {
|
||||
case 1:
|
||||
continue L;
|
||||
L:
|
||||
default:
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
static method main() → dynamic {
|
||||
#L1:
|
||||
{
|
||||
core::int #t1 = -1;
|
||||
final core::int #0#0 = 0;
|
||||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0)
|
||||
#t1 = 0;
|
||||
else
|
||||
#t1 = 1;
|
||||
switch(#t1) {
|
||||
#L2:
|
||||
case #C2:
|
||||
{
|
||||
{
|
||||
continue #L3;
|
||||
}
|
||||
}
|
||||
#L3:
|
||||
case #C1:
|
||||
default:
|
||||
{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constants {
|
||||
#C1 = 1
|
||||
#C2 = 0
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
static method main() → dynamic {
|
||||
#L1:
|
||||
{
|
||||
core::int #t1 = -1;
|
||||
final core::int #0#0 = 0;
|
||||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0)
|
||||
#t1 = 0;
|
||||
else
|
||||
#t1 = 1;
|
||||
switch(#t1) {
|
||||
#L2:
|
||||
case #C2:
|
||||
{
|
||||
{
|
||||
continue #L3;
|
||||
}
|
||||
}
|
||||
#L3:
|
||||
case #C1:
|
||||
default:
|
||||
{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constants {
|
||||
#C1 = 1
|
||||
#C2 = 0
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
main() {}
|
|
@ -0,0 +1 @@
|
|||
main() {}
|
33
pkg/front_end/testcases/patterns/issue51553.dart.weak.expect
Normal file
33
pkg/front_end/testcases/patterns/issue51553.dart.weak.expect
Normal file
|
@ -0,0 +1,33 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
static method main() → dynamic {
|
||||
#L1:
|
||||
{
|
||||
core::int #t1 = -1;
|
||||
final core::int #0#0 = 0;
|
||||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0)
|
||||
#t1 = 0;
|
||||
else
|
||||
#t1 = 1;
|
||||
switch(#t1) {
|
||||
#L2:
|
||||
case #C2:
|
||||
{
|
||||
{
|
||||
continue #L3;
|
||||
}
|
||||
}
|
||||
#L3:
|
||||
case #C1:
|
||||
default:
|
||||
{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constants {
|
||||
#C1 = 1
|
||||
#C2 = 0
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
static method main() → dynamic {
|
||||
#L1:
|
||||
{
|
||||
core::int #t1 = -1;
|
||||
final core::int #0#0 = 0;
|
||||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0)
|
||||
#t1 = 0;
|
||||
else
|
||||
#t1 = 1;
|
||||
switch(#t1) {
|
||||
#L2:
|
||||
case #C2:
|
||||
{
|
||||
{
|
||||
continue #L3;
|
||||
}
|
||||
}
|
||||
#L3:
|
||||
case #C1:
|
||||
default:
|
||||
{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constants {
|
||||
#C1 = 1
|
||||
#C2 = 0
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
import self as self;
|
||||
|
||||
static method main() → dynamic
|
||||
;
|
|
@ -0,0 +1,33 @@
|
|||
library /*isNonNullableByDefault*/;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
static method main() → dynamic {
|
||||
#L1:
|
||||
{
|
||||
core::int #t1 = -1;
|
||||
final core::int #0#0 = 0;
|
||||
if(#C1 =={core::num::==}{(core::Object) → core::bool} #0#0)
|
||||
#t1 = 0;
|
||||
else
|
||||
#t1 = 1;
|
||||
switch(#t1) {
|
||||
#L2:
|
||||
case #C2:
|
||||
{
|
||||
{
|
||||
continue #L3;
|
||||
}
|
||||
}
|
||||
#L3:
|
||||
case #C1:
|
||||
default:
|
||||
{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constants {
|
||||
#C1 = 1
|
||||
#C2 = 0
|
||||
}
|
Loading…
Reference in a new issue