ed1633ac6c
Change-Id: I4cf3a34e73e754c9f783585612fa6c7f277ac5dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293523 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com>
129 lines
2.8 KiB
Dart
129 lines
2.8 KiB
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.
|
|
|
|
// SharedOptions=--enable-experiment=patterns,records
|
|
|
|
/// A variable declared by a pattern is in scope in the pattern but can't be
|
|
/// used in constant expression inside the pattern.
|
|
|
|
void testSwitchStatement(int x) {
|
|
switch (x) {
|
|
case var a && == a:
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
'error';
|
|
case == b && var b:
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
'error';
|
|
}
|
|
}
|
|
|
|
void testSwitchStatementInScope(int x) {
|
|
const a = 'outer';
|
|
const b = 'outer';
|
|
|
|
switch (x) {
|
|
case var a && == a:
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
'error';
|
|
case == b && var b:
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
'error';
|
|
}
|
|
}
|
|
|
|
String testSwitchExpression(int x) {
|
|
return switch (x) {
|
|
var a && == a => 'error',
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
== b && var b => 'error',
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
_ => 'other'
|
|
};
|
|
}
|
|
|
|
String testSwitchExpressionInScope(int x) {
|
|
const a = 'outer';
|
|
const b = 'outer';
|
|
|
|
return switch (x) {
|
|
var a && == a => 'error',
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
== b && var b => 'error',
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
_ => 'other'
|
|
};
|
|
}
|
|
|
|
void testIfCaseStatement(int x) {
|
|
if (x case var a && == a) {}
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
|
|
if (x case == b && var b) {}
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
}
|
|
|
|
void testIfCaseStatementInScope(int x) {
|
|
const a = 'outer';
|
|
const b = 'outer';
|
|
|
|
if (x case var a && == a) {}
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
|
|
if (x case == b && var b) {}
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
}
|
|
|
|
List<String> testIfCaseElement(int x) {
|
|
return [
|
|
if (x case var a && == a) 'one',
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
if (x case == b && var b) 'two'
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
];
|
|
}
|
|
|
|
List<String> testIfCaseElementInScope(int x) {
|
|
const a = 'outer';
|
|
const b = 'outer';
|
|
|
|
return [
|
|
if (x case var a && == a) 'one',
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
if (x case == b && var b) 'two'
|
|
// ^
|
|
// [analyzer] unspecified
|
|
// [cfe] unspecified
|
|
];
|
|
}
|