[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:
Johnni Winther 2023-03-06 10:13:31 +00:00 committed by Commit Queue
parent 874e7ee056
commit 6f752165ea
10 changed files with 190 additions and 3 deletions

View file

@ -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(

View 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:
}
}

View 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
}

View 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
}

View file

@ -0,0 +1 @@
main() {}

View 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
}

View 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
}

View file

@ -0,0 +1,5 @@
library /*isNonNullableByDefault*/;
import self as self;
static method main() → dynamic
;

View 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
}