| Index: tests/language_2/covariant_subtyping_with_substitution_test.dart
|
| diff --git a/tests/language_2/covariant_subtyping_with_substitution_test.dart b/tests/language_2/covariant_subtyping_with_substitution_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2160f8467f3e2d179fef0dc2c43dd6c26e87c8dc
|
| --- /dev/null
|
| +++ b/tests/language_2/covariant_subtyping_with_substitution_test.dart
|
| @@ -0,0 +1,39 @@
|
| +// 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';
|
| +
|
| +typedef F<T>(T x);
|
| +
|
| +class B<T> {
|
| + void f(F<T> x) {}
|
| +}
|
| +
|
| +abstract class I<U> {
|
| + void f(U x);
|
| +}
|
| +
|
| +class C<V> extends B<V> implements I<F<V>> {}
|
| +
|
| +void acceptsObject(Object o) {}
|
| +
|
| +void acceptsNum(num n) {}
|
| +
|
| +bool isTypeError(e) => e is TypeError;
|
| +
|
| +void g(I<F<num>> i) {
|
| + i.f(acceptsObject);
|
| + // i.f has static type (F<num>)->void, or ((num)->void)->void. Which means we
|
| + // are statically allowed to pass acceptsNum to it. However, if i's runtime
|
| + // type is C<Object>, then it extends B<Object>, so its f function requires
|
| + // its argument to be F<Object>. This means that passing acceptsNum to f
|
| + // would violate soundness (since acceptsNum has type F<num>, and F<num> is a
|
| + // supertype of F<Object>). So we expect a type error here.
|
| + Expect.throws(() {
|
| + i.f(acceptsNum);
|
| + }, isTypeError);
|
| +}
|
| +
|
| +void main() {
|
| + g(new C<Object>());
|
| +}
|
|
|