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 |
| 5 // Dart test for type checks involving the void type. |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 |
| 9 class A<T> { |
| 10 T x; |
| 11 foo(T x) {} |
| 12 T bar(T f()) { |
| 13 T tmp = f(); |
| 14 return tmp; |
| 15 } |
| 16 |
| 17 gee(T f()) { |
| 18 x = bar(f); |
| 19 } |
| 20 |
| 21 Object xAsObject() => x; |
| 22 } |
| 23 |
| 24 void voidFun() => 499; |
| 25 int intFun() => 42; |
| 26 |
| 27 main() { |
| 28 A<void> a = new A<void>(); |
| 29 a.foo(a.x); /// 00: static type warning |
| 30 a.bar(voidFun); |
| 31 Expect.equals(null, a.xAsObject()); |
| 32 a.x = a.bar(voidFun); /// 01: static type warning |
| 33 a.gee(voidFun); // But we can do it through `gee`. |
| 34 Expect.equals(499, a.xAsObject()); |
| 35 a.gee(intFun); // We can also pass in an int function. |
| 36 Expect.equals(42, a.xAsObject()); |
| 37 } |
OLD | NEW |