Files
sdk/pkg/front_end/testcases/patterns/issue52192.dart
T
Johnni Winther 9b42e2d166 [cfe] Generate covariant checks in pattern matching
Closes #52192

Change-Id: Iaac816273fb80eaf166fc300b2b3367f1a592d3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302223
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2023-05-09 11:02:45 +00:00

45 lines
865 B
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.
int callCount = 0;
abstract class A<X> {
void Function(X) get g;
}
class B implements A<int> {
void Function(int) get g => (int i) => callCount++;
}
void foo(Object o, num value) {
switch (o) {
case B(g: _) && A<num>(g: var f):
f(value);
}
}
void main() {
expect(0, callCount);
throws(() => foo(B(), 25.7));
expect(0, callCount);
throws(() => foo(B(), 1));
expect(0, callCount);
}
expect(expected, actual) {
if (expected != actual) {
throw 'Expected $expected, actual $actual';
}
}
throws(void Function() f) {
try {
f();
} catch (e) {
print(e);
return;
}
throw 'No exception thrown';
}