OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "dart:async"; | 5 import "dart:async"; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
8 | 8 |
9 Future foo1() async { | 9 Future foo1() async { |
10 return 3; | 10 return 3; |
11 } | 11 } |
12 | 12 |
13 Future<int> foo2() async { | 13 Future<int> foo2() async { |
14 return 3; | 14 return 3; |
15 } | 15 } |
16 | 16 |
17 Future<int> //# wrongTypeParameter: static type warning, dynamic type error | 17 Future<int> //# wrongTypeParameter: compile-time error |
18 foo3() async { | 18 foo3() async { |
19 return "String"; | 19 return "String"; |
20 } | 20 } |
21 | 21 |
22 // Future<int, String> is treated like Future<dynamic> | 22 Future<int, String> //# tooManyTypeParameters: compile-time error |
23 Future<int, String> //# tooManyTypeParameters: static type warning | |
24 foo4() async { | 23 foo4() async { |
25 return "String"; | 24 return "String"; |
26 } | 25 } |
27 | 26 |
28 int //# wrongReturnType: static type warning, dynamic type error | 27 int //# wrongReturnType: compile-time error |
29 foo5() async { | 28 foo5() async { |
30 return 3; | 29 return 3; |
31 } | 30 } |
32 | 31 |
33 Future<int> foo6() async { | 32 Future<int> foo6() async { |
34 // This is fine, the future is flattened | 33 // This is fine, the future is flattened |
35 return new Future<int>.value(3); | 34 return new Future<int>.value(3); |
36 } | 35 } |
37 | 36 |
38 Future<Future<int>> //# nestedFuture: static type warning, dynamic type error | 37 Future<Future<int>> //# nestedFuture: compile-time error |
39 foo7() async { | 38 foo7() async { |
40 return new Future<int>.value(3); | 39 return new Future<int>.value(3); |
41 } | 40 } |
42 | 41 |
43 Iterable<int> foo8() sync* { | 42 Iterable<int> foo8() sync* { |
44 yield 1; | 43 yield 1; |
45 // Can only have valueless return in sync* functions. | 44 // Can only have valueless return in sync* functions. |
46 return | 45 return |
47 8 //# return_value_sync_star: compile-time error | 46 8 //# return_value_sync_star: compile-time error |
48 ; | 47 ; |
(...skipping 15 matching lines...) Expand all Loading... |
64 Expect.equals(3, await foo5()); | 63 Expect.equals(3, await foo5()); |
65 Expect.equals(3, await await foo6()); | 64 Expect.equals(3, await await foo6()); |
66 Expect.equals(3, await await foo7()); | 65 Expect.equals(3, await await foo7()); |
67 Expect.listEquals([1], foo8().toList()); | 66 Expect.listEquals([1], foo8().toList()); |
68 Expect.listEquals([1], await foo9().toList()); | 67 Expect.listEquals([1], await foo9().toList()); |
69 } | 68 } |
70 | 69 |
71 main() { | 70 main() { |
72 asyncTest(test); | 71 asyncTest(test); |
73 } | 72 } |
OLD | NEW |