dart-sdk/tests/language/patterns/switch_case_scope_error_test.dart
Robert Nystrom b9b30b5883 Add language tests for pattern variable scoping.
This doesn't comprehensively cover everything we should test around
pattern variable scopes, but I wanted to cover most of the tricky
behavior around variables in cases that share a body, along with some
other edge cases that I thought of while speccing that out.

Change-Id: I64fff7b4a9a30b00801fbf37b52f07799ef0fd35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/268370
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
2022-11-23 00:05:47 +00:00

32 lines
877 B
Dart

// Copyright (c) 2022, 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
main() {
var local = 'local';
// If cases sharing a body don't agree on a variable's finality, it is still
// considered in scope and an error to use.
switch ('value') {
case final int local:
case int local:
print(local);
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
// If cases sharing a body don't agree on a variable's type, it is still
// considered in scope and an error to use.
switch ('value') {
case bool local:
case int local:
print(local);
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}