mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:19:48 +00:00
82b78916fd
Change-Id: If31c487e3ebe2c1ae847aff7c8994580b8b6f2f6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309660 Reviewed-by: Alexander Thomas <athom@google.com> Commit-Queue: Alexander Thomas <athom@google.com>
127 lines
2.7 KiB
Dart
127 lines
2.7 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.
|
|
|
|
/// 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
|
|
];
|
|
}
|