| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 import 'package:expect/expect.dart'; |
| 5 |
| 6 typedef F<T>(T x); |
| 7 |
| 8 class B<T> { |
| 9 void f(F<T> x) {} |
| 10 } |
| 11 |
| 12 abstract class I<U> { |
| 13 void f(U x); |
| 14 } |
| 15 |
| 16 class C<V> extends B<V> implements I<F<V>> {} |
| 17 |
| 18 void acceptsObject(Object o) {} |
| 19 |
| 20 void acceptsNum(num n) {} |
| 21 |
| 22 bool isTypeError(e) => e is TypeError; |
| 23 |
| 24 void g(I<F<num>> i) { |
| 25 i.f(acceptsObject); |
| 26 // i.f has static type (F<num>)->void, or ((num)->void)->void. Which means we |
| 27 // are statically allowed to pass acceptsNum to it. However, if i's runtime |
| 28 // type is C<Object>, then it extends B<Object>, so its f function requires |
| 29 // its argument to be F<Object>. This means that passing acceptsNum to f |
| 30 // would violate soundness (since acceptsNum has type F<num>, and F<num> is a |
| 31 // supertype of F<Object>). So we expect a type error here. |
| 32 Expect.throws(() { |
| 33 i.f(acceptsNum); |
| 34 }, isTypeError); |
| 35 } |
| 36 |
| 37 void main() { |
| 38 g(new C<Object>()); |
| 39 } |
| OLD | NEW |