9f4f7faaa4
Closes https://github.com/dart-lang/sdk/issues/51604 Closes https://github.com/dart-lang/sdk/issues/51962 Part of https://github.com/dart-lang/sdk/issues/49749 Change-Id: I9ada7a3a0194964af5c9e2afea1c2ea3ead67641 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292890 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
113 lines
1.9 KiB
Dart
113 lines
1.9 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.
|
|
|
|
test1(dynamic x) {
|
|
switch (x) {
|
|
case 0:
|
|
case int i:
|
|
return i; // Error.
|
|
case String s:
|
|
case "foo":
|
|
return s; // Error.
|
|
case double d:
|
|
case < 3.14:
|
|
return d; // Error.
|
|
case == false:
|
|
case bool b:
|
|
return b; // Error.
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
test2(dynamic x) {
|
|
switch (x) {
|
|
case <= 0:
|
|
continue L;
|
|
L:
|
|
case int i2:
|
|
return i2; // Error.
|
|
case String s2:
|
|
default:
|
|
return s2; // Error.
|
|
}
|
|
}
|
|
|
|
test3(dynamic x) {
|
|
switch (x) {
|
|
case <= 0:
|
|
continue L;
|
|
L:
|
|
case int i3:
|
|
case [int i3]:
|
|
return i3; // Error.
|
|
case String s3:
|
|
case [String s3]:
|
|
default:
|
|
return s3; // Error.
|
|
}
|
|
}
|
|
|
|
test4(dynamic x) {
|
|
switch (x) {
|
|
case <= 0:
|
|
continue L;
|
|
L:
|
|
case int i4:
|
|
case [double i4]:
|
|
return i4; // Error.
|
|
case String s4:
|
|
case [final String s4]:
|
|
default:
|
|
return s4; // Error.
|
|
}
|
|
}
|
|
|
|
test5(dynamic x) {
|
|
switch (x) {
|
|
case <= 0:
|
|
continue L;
|
|
L:
|
|
case int i5 when i5 == 1: // Ok.
|
|
return null;
|
|
case String s5 when s5 == "foo": // Ok.
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
test6(dynamic x, bool b) {
|
|
switch (x) {
|
|
case <= 0:
|
|
continue L;
|
|
L:
|
|
case int i6:
|
|
if (b) {
|
|
return i6; // Error.
|
|
}
|
|
case String s6:
|
|
default:
|
|
if (b) {
|
|
if (b) {
|
|
return s6; // Error.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
test7(dynamic x) {
|
|
switch (x) {
|
|
case <= 0:
|
|
continue L;
|
|
L:
|
|
case int i7 when i7 == 1: // Ok.
|
|
int i7 = 1;
|
|
return i7; // Still ok.
|
|
case String s7 when s7 == "foo": // Ok.
|
|
default:
|
|
String s7 = "foo";
|
|
return s7; // Still ok.
|
|
}
|
|
}
|