dart-sdk/tests/language_2/forwarding_stub_tearoff_generic_test.dart
Paul Berry 381c43e89f Add language_2 tests to verify behavior of tear-offs of forwarding stubs.
Change-Id: I4dec23a3fde4332b87fc36d939d34409f86264a4
Reviewed-on: https://dart-review.googlesource.com/27502
Reviewed-by: Samir Jindel <sjindel@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-12-08 16:51:20 +00:00

44 lines
1 KiB
Dart

// Copyright (c) 2017, 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.
import "package:expect/expect.dart";
class A {}
class B extends A {}
class C {
void f(B x) {}
}
abstract class I<T> {
void f(T x);
}
// D contains a forwarding stub for f which ensures that `x` is type checked.
class D extends C implements I<B> {}
void checkStubTearoff(dynamic tearoff) {
// Since the stub's parameter is covariant, its type should be reified as
// Object.
Expect.isTrue(tearoff is void Function(Object));
// Verify that the appropriate runtime check occurs.
tearoff(new B()); // No error
Expect.throwsTypeError(() {
tearoff(new A());
});
}
main() {
// The same forwarding stub should be torn off from D regardless of what
// interface is used to tear it off.
D d = new D();
C c = d;
I i = d;
checkStubTearoff(d.f);
checkStubTearoff(c.f);
checkStubTearoff(i.f);
}