OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 | 5 |
6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 topLevelFunction() async { } | 10 topLevelFunction() async { } |
11 | 11 |
12 Future<int> topLevelWithParameter(int a) async { | 12 Future<int> topLevelWithParameter(int a) async { |
13 return 7 + a; | 13 return 7 + a; |
14 } | 14 } |
15 | 15 |
16 int topLevelWithParameterWrongType(int a) async { | 16 int /// type-mismatch2: static type warning, dynamic type error |
| 17 topLevelWithParameterWrongType(int a) async { |
17 return 7 + a; | 18 return 7 + a; |
18 } | 19 } |
19 | 20 |
20 var what = 'async getter'; | 21 var what = 'async getter'; |
21 Future<String> get topLevelGetter async { | 22 Future<String> get topLevelGetter async { |
22 return 'I want to be an ${what}'; | 23 return 'I want to be an ${what}'; |
23 } | 24 } |
24 | 25 |
25 class A { | 26 class A { |
26 static int staticVar = 1; | 27 static int staticVar = 1; |
27 | 28 |
28 static staticMethod(int param) async => staticVar + param; | 29 static staticMethod(int param) async => staticVar + param; |
29 static get staticGetter async => staticVar + 3; | 30 static get staticGetter async => staticVar + 3; |
30 | 31 |
31 int _x; | 32 int _x; |
32 A(this._x); | 33 A(this._x); |
33 | 34 |
34 A.fail() async; /// constructor2: compile-time error | 35 A.fail() async; /// constructor2: compile-time error |
35 factory A.create() async {return null; } /// constructor3: compile-time error | 36 factory A.create() async {return null; } /// constructor3: compile-time error |
36 | 37 |
37 int someMethod(int param1, int param2, int param3) async => _x + param2; | 38 int someMethod(int param1, int param2, int param3) async => _x + param2; /// t
ype-mismatch3: static type warning, dynamic type error |
38 int get getter async { return 5 + _x; } | 39 int get getter async { return 5 + _x; } /// type-mismatch4: static type warnin
g, dynamic type error |
39 operator+(A other) async { | 40 operator+(A other) async { |
40 return new A(_x + other._x); | 41 return new A(_x + other._x); |
41 } | 42 } |
42 | 43 |
43 get value => _x; | 44 get value => _x; |
44 } | 45 } |
45 | 46 |
46 class B { | 47 class B { |
47 final _y; | 48 final _y; |
48 const B._internal(this._y); | 49 const B._internal(this._y); |
49 const factory B.createConst(int y) async = A._internal; /// constructor4: com
pile-time error | 50 const factory B.createConst(int y) async = A._internal; /// constructor4: com
pile-time error |
50 | 51 |
51 B() : _y = null; | 52 B() : _y = null; |
52 | 53 |
53 set dontDoThat(value) async {} /// setter1: compile-time error | 54 set dontDoThat(value) async {} /// setter1: compile-time error |
54 } | 55 } |
55 | 56 |
56 | 57 |
57 main() { | 58 main() { |
58 var asyncReturn; | 59 var asyncReturn; |
59 | 60 |
60 asyncReturn = topLevelFunction(); | 61 asyncReturn = topLevelFunction(); |
61 Expect.isTrue(asyncReturn is Future); | 62 Expect.isTrue(asyncReturn is Future); |
62 | 63 |
63 int a1 = topLevelWithParameter(2); /// type-mismatch1: static type warning, d
ynamic type error | 64 int a1 = topLevelWithParameter(2); /// type-mismatch1: static type warning, d
ynamic type error |
64 int a2 = topLevelWithParameterWrongType(2); /// type-mismatch2: static type w
arning, dynamic type error | 65 int a2 = topLevelWithParameterWrongType(2); /// type-mismatch2: continued |
65 asyncReturn = topLevelWithParameter(4); | 66 asyncReturn = topLevelWithParameter(4); |
66 Expect.isTrue(asyncReturn is Future); | 67 Expect.isTrue(asyncReturn is Future); |
67 asyncReturn.then((int result) => Expect.equals(result, 11)); | 68 asyncReturn.then((int result) => Expect.equals(result, 11)); |
68 | 69 |
69 asyncReturn = topLevelGetter; | 70 asyncReturn = topLevelGetter; |
70 Expect.isTrue(asyncReturn is Future); | 71 Expect.isTrue(asyncReturn is Future); |
71 asyncReturn.then((String result) => | 72 asyncReturn.then((String result) => |
72 Expect.stringEquals(result, 'I want to be an async getter')); | 73 Expect.stringEquals(result, 'I want to be an async getter')); |
73 | 74 |
74 asyncReturn = A.staticMethod(2); | 75 asyncReturn = A.staticMethod(2); |
75 Expect.isTrue(asyncReturn is Future); | 76 Expect.isTrue(asyncReturn is Future); |
76 asyncReturn.then((int result) => Expect.equals(result, 3)); | 77 asyncReturn.then((int result) => Expect.equals(result, 3)); |
77 | 78 |
78 asyncReturn = A.staticGetter; | 79 asyncReturn = A.staticGetter; |
79 Expect.isTrue(asyncReturn is Future); | 80 Expect.isTrue(asyncReturn is Future); |
80 asyncReturn.then((int result) => Expect.equals(result, 4)); | 81 asyncReturn.then((int result) => Expect.equals(result, 4)); |
81 | 82 |
82 A a = new A(13); | 83 A a = new A(13); |
83 | 84 |
84 asyncReturn = a.someMethod(1,2,3); /// type-mismatch3: static type warning, d
ynamic type error | 85 asyncReturn = a.someMethod(1,2,3); /// type-mismatch3: continued |
85 Expect.isTrue(asyncReturn is Future); /// type-mismatch3: continued | 86 Expect.isTrue(asyncReturn is Future); /// type-mismatch3: continued |
86 asyncReturn.then((int result) => Expect.equals(result, 15)); /// type-mismatc
h3: continued | 87 asyncReturn.then((int result) => Expect.equals(result, 15)); /// type-mismatc
h3: continued |
87 | 88 |
88 asyncReturn = a.getter; /// type-mismatch4: static type warning, dynamic type
error | 89 asyncReturn = a.getter; /// type-mismatch4: continued |
89 Expect.isTrue(asyncReturn is Future); /// type-mismatch4: continued | 90 Expect.isTrue(asyncReturn is Future); /// type-mismatch4: continued |
90 asyncReturn.then((int result) => Expect.equals(result, 18)); /// type-mismatc
h4: continued | 91 asyncReturn.then((int result) => Expect.equals(result, 18)); /// type-mismatc
h4: continued |
91 | 92 |
92 var b = new A(9); | 93 var b = new A(9); |
93 asyncReturn = a + b; | 94 asyncReturn = a + b; |
94 Expect.isTrue(asyncReturn is Future); | 95 Expect.isTrue(asyncReturn is Future); |
95 asyncReturn.then((A result) => Expect.equals(result.value, 22)); | 96 asyncReturn.then((A result) => Expect.equals(result.value, 22)); |
96 | 97 |
97 var foo = 17; | 98 var foo = 17; |
98 bar(int p1, p2) async { | 99 bar(int p1, p2) async { |
(...skipping 20 matching lines...) Expand all Loading... |
119 b2.dontDoThat = 4; /// setter1: compile-time error | 120 b2.dontDoThat = 4; /// setter1: compile-time error |
120 | 121 |
121 var checkAsync = (var someFunc) { | 122 var checkAsync = (var someFunc) { |
122 var toTest = someFunc(); | 123 var toTest = someFunc(); |
123 Expect.isTrue(toTest is Future); | 124 Expect.isTrue(toTest is Future); |
124 toTest.then((int result) => Expect.equals(result, 4)); | 125 toTest.then((int result) => Expect.equals(result, 4)); |
125 }; | 126 }; |
126 checkAsync(() async => 4); | 127 checkAsync(() async => 4); |
127 | 128 |
128 } | 129 } |
OLD | NEW |