mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 15:01:29 +00:00
236ea5bb44
Change-Id: Ib67f8ae239b89bf56efc059054b6430e27a0e66f Reviewed-on: https://dart-review.googlesource.com/34922 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
48 lines
1.2 KiB
Dart
48 lines
1.2 KiB
Dart
// Copyright (c) 2018, 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 B2 extends A {}
|
|
|
|
class C {
|
|
void f(covariant B x) {}
|
|
}
|
|
|
|
abstract class I {
|
|
void f(A x);
|
|
}
|
|
|
|
// This class does not require a forwarding stub; the interface of D.f is (A) ->
|
|
// void and the implementation has signature (covariant B) -> void. The
|
|
// implementation satisfies the interface thanks to the presence of the
|
|
// "covariant" keyword.
|
|
class D extends C implements I {}
|
|
|
|
main() {
|
|
var d = new D();
|
|
I i = d;
|
|
A a = new A();
|
|
B b = new B();
|
|
B2 b2Null = null;
|
|
|
|
// The following two lines are statically ok because the type B2 is assignable
|
|
// to the type A. There should be no runtime error because the actual value
|
|
// at runtime is `null`, which may be assigned to A.
|
|
d.f(b2Null);
|
|
i.f(b2Null);
|
|
|
|
void Function(Object) g = d.f; // Ok; D.f reified as (Object) -> void
|
|
Expect.throwsTypeError(() {
|
|
d.f(a);
|
|
});
|
|
Expect.throwsTypeError(() {
|
|
i.f(a);
|
|
});
|
|
}
|