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 var a = new A<void>(); | |
Lasse Reichstein Nielsen
2017/02/21 09:37:04
var a = ... -> A<void> a = ...
floitsch
2017/02/22 14:44:43
Done.
| |
29 a.foo(a.x); /// 00: error | |
30 a.bar(voidFun); | |
31 Expect.equals(null, a.xAsObject()); | |
32 var t = a.bar(voidFun); /// 01: error | |
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 |