Adjust type_parameter_test to expect caller-side check on tearoff

language/covariant/type_parameter_test.dart performed a tearoff which
should incur a run-time error (because the dynamic type of the
tearoff is not a subtype of the static type, so it would be a
soundness violation to pass that value on to the next step of
evaluation).

Change-Id: Ia4ec813606e711cab0bdcc68d24bbac3c9a2d8c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209910
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
This commit is contained in:
Erik Ernst 2021-08-11 16:37:51 +00:00 committed by commit-bot@chromium.org
parent 15e5ec1762
commit cc84bb3e28

View file

@ -23,16 +23,18 @@ class C extends B<A> {
main() {
// Dynamic method calls should always have their type arguments checked.
dynamic d = new C();
Expect.throwsTypeError(() => d.f1<Object>()); //# 01: ok
Expect.throwsTypeError(() => d.f1<Object>());
// Closure calls should have any type arguments marked "genericCovariantImpl"
// checked.
// Closurization is subject to a caller-side check. The naive static type of
// `b.f2` is `void Function<U extends Object>()`, but the run-time type is
// `void Function<U extends A>()`, and that is not a subtype of the former.
B<Object> b = new C();
void Function<U extends Object>() f = b.f2;
Expect.throwsTypeError(() => f<Object>()); //# 02: ok
Expect.throws(() => b.f2);
// Interface calls should have any type arguments marked
// "genericCovariantImpl" checked provided that the corresponding type
// argument on the interface target is marked "genericCovariantInterface".
Expect.throwsTypeError(() => b.f2<Object>()); //# 03: ok
B<A> b2 = new C();
Function g = b2.f2;
Expect.throwsTypeError(() => g<Object>());
}