OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import "dart:async"; | |
6 import "package:expect/expect.dart"; | |
7 import "package:async_helper/async_helper.dart"; | |
8 | |
9 Future foo1() async { | |
10 return 3; | |
11 } | |
12 | |
13 Future<int> foo2() async { | |
14 return 3; | |
15 } | |
16 | |
17 Future<int> //# wrongTypeParameter: compile-time error | |
18 foo3() async { | |
19 return "String"; | |
20 } | |
21 | |
22 Future<int, String> //# tooManyTypeParameters: compile-time error | |
23 foo4() async { | |
24 return "String"; | |
25 } | |
26 | |
27 int //# wrongReturnType: compile-time error | |
28 foo5() async { | |
29 return 3; | |
30 } | |
31 | |
32 Future<int> foo6() async { | |
33 // This is fine, the future is flattened | |
34 return new Future<int>.value(3); | |
35 } | |
36 | |
37 Future<Future<int>> //# nestedFuture: compile-time error | |
38 foo7() async { | |
39 return new Future<int>.value(3); | |
40 } | |
41 | |
42 Iterable<int> foo8() sync* { | |
43 yield 1; | |
44 // Can only have valueless return in sync* functions. | |
45 return | |
46 8 //# return_value_sync_star: compile-time error | |
47 ; | |
48 } | |
49 | |
50 Stream<int> foo9() async* { | |
51 yield 1; | |
52 // Can only have valueless return in async* functions. | |
53 return | |
54 8 //# return_value_sync_star: compile-time error | |
55 ; | |
56 } | |
57 | |
58 test() async { | |
59 Expect.equals(3, await foo1()); | |
60 Expect.equals(3, await foo2()); | |
61 Expect.equals("String", await foo3()); | |
62 Expect.equals("String", await foo4()); | |
63 Expect.equals(3, await foo5()); | |
64 Expect.equals(3, await await foo6()); | |
65 Expect.equals(3, await await foo7()); | |
66 Expect.listEquals([1], foo8().toList()); | |
67 Expect.listEquals([1], await foo9().toList()); | |
68 } | |
69 | |
70 main() { | |
71 asyncTest(test); | |
72 } | |
OLD | NEW |