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 /// type-mismatch2: static type warning, dynamic type error | 16 int //# type-mismatch2: static type warning, dynamic type error |
17 topLevelWithParameterWrongType(int a) async { | 17 topLevelWithParameterWrongType(int a) async { |
18 return 7 + a; | 18 return 7 + a; |
19 } | 19 } |
20 | 20 |
21 var what = 'async getter'; | 21 var what = 'async getter'; |
22 Future<String> get topLevelGetter async { | 22 Future<String> get topLevelGetter async { |
23 return 'I want to be an ${what}'; | 23 return 'I want to be an ${what}'; |
24 } | 24 } |
25 | 25 |
26 class A { | 26 class A { |
27 static int staticVar = 1; | 27 static int staticVar = 1; |
28 | 28 |
29 static staticMethod(int param) async => staticVar + param; | 29 static staticMethod(int param) async => staticVar + param; |
30 static get staticGetter async => staticVar + 3; | 30 static get staticGetter async => staticVar + 3; |
31 | 31 |
32 int _x; | 32 int _x; |
33 A(this._x); | 33 A(this._x); |
34 | 34 |
35 A.fail() async; /// constructor2: compile-time error | 35 A.fail() async; //# constructor2: compile-time error |
36 factory A.create() async {return null; } /// constructor3: compile-time error | 36 factory A.create() async {return null; } //# constructor3: compile-time error |
37 | 37 |
38 int someMethod(int param1, int param2, int param3) async => _x + param2; /// t
ype-mismatch3: static type warning, dynamic type error | 38 int someMethod(int param1, int param2, int param3) async => _x + param2; //# t
ype-mismatch3: static type warning, dynamic type error |
39 int get getter async { return 5 + _x; } /// type-mismatch4: static type warnin
g, dynamic type error | 39 int get getter async { return 5 + _x; } //# type-mismatch4: static type warnin
g, dynamic type error |
40 operator+(A other) async { | 40 operator+(A other) async { |
41 return new A(_x + other._x); | 41 return new A(_x + other._x); |
42 } | 42 } |
43 | 43 |
44 get value => _x; | 44 get value => _x; |
45 } | 45 } |
46 | 46 |
47 class B { | 47 class B { |
48 final _y; | 48 final _y; |
49 const B._internal(this._y); | 49 const B._internal(this._y); |
50 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 |
51 | 51 |
52 B() : _y = null; | 52 B() : _y = null; |
53 | 53 |
54 set dontDoThat(value) async {} /// setter1: compile-time error | 54 set dontDoThat(value) async {} //# setter1: compile-time error |
55 } | 55 } |
56 | 56 |
57 | 57 |
58 main() { | 58 main() { |
59 var asyncReturn; | 59 var asyncReturn; |
60 | 60 |
61 asyncReturn = topLevelFunction(); | 61 asyncReturn = topLevelFunction(); |
62 Expect.isTrue(asyncReturn is Future); | 62 Expect.isTrue(asyncReturn is Future); |
63 | 63 |
64 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 |
65 int a2 = topLevelWithParameterWrongType(2); /// type-mismatch2: continued | 65 int a2 = topLevelWithParameterWrongType(2); //# type-mismatch2: continued |
66 asyncReturn = topLevelWithParameter(4); | 66 asyncReturn = topLevelWithParameter(4); |
67 Expect.isTrue(asyncReturn is Future); | 67 Expect.isTrue(asyncReturn is Future); |
68 asyncReturn.then((int result) => Expect.equals(result, 11)); | 68 asyncReturn.then((int result) => Expect.equals(result, 11)); |
69 | 69 |
70 asyncReturn = topLevelGetter; | 70 asyncReturn = topLevelGetter; |
71 Expect.isTrue(asyncReturn is Future); | 71 Expect.isTrue(asyncReturn is Future); |
72 asyncReturn.then((String result) => | 72 asyncReturn.then((String result) => |
73 Expect.stringEquals(result, 'I want to be an async getter')); | 73 Expect.stringEquals(result, 'I want to be an async getter')); |
74 | 74 |
75 asyncReturn = A.staticMethod(2); | 75 asyncReturn = A.staticMethod(2); |
76 Expect.isTrue(asyncReturn is Future); | 76 Expect.isTrue(asyncReturn is Future); |
77 asyncReturn.then((int result) => Expect.equals(result, 3)); | 77 asyncReturn.then((int result) => Expect.equals(result, 3)); |
78 | 78 |
79 asyncReturn = A.staticGetter; | 79 asyncReturn = A.staticGetter; |
80 Expect.isTrue(asyncReturn is Future); | 80 Expect.isTrue(asyncReturn is Future); |
81 asyncReturn.then((int result) => Expect.equals(result, 4)); | 81 asyncReturn.then((int result) => Expect.equals(result, 4)); |
82 | 82 |
83 A a = new A(13); | 83 A a = new A(13); |
84 | 84 |
85 asyncReturn = a.someMethod(1,2,3); /// type-mismatch3: continued | 85 asyncReturn = a.someMethod(1,2,3); //# type-mismatch3: continued |
86 Expect.isTrue(asyncReturn is Future); /// type-mismatch3: continued | 86 Expect.isTrue(asyncReturn is Future); //# type-mismatch3: continued |
87 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 |
88 | 88 |
89 asyncReturn = a.getter; /// type-mismatch4: continued | 89 asyncReturn = a.getter; //# type-mismatch4: continued |
90 Expect.isTrue(asyncReturn is Future); /// type-mismatch4: continued | 90 Expect.isTrue(asyncReturn is Future); //# type-mismatch4: continued |
91 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 |
92 | 92 |
93 var b = new A(9); | 93 var b = new A(9); |
94 asyncReturn = a + b; | 94 asyncReturn = a + b; |
95 Expect.isTrue(asyncReturn is Future); | 95 Expect.isTrue(asyncReturn is Future); |
96 asyncReturn.then((A result) => Expect.equals(result.value, 22)); | 96 asyncReturn.then((A result) => Expect.equals(result.value, 22)); |
97 | 97 |
98 var foo = 17; | 98 var foo = 17; |
99 bar(int p1, p2) async { | 99 bar(int p1, p2) async { |
100 var z = 8; | 100 var z = 8; |
101 return p2 + z + foo; | 101 return p2 + z + foo; |
102 } | 102 } |
103 asyncReturn = bar(1,2); | 103 asyncReturn = bar(1,2); |
104 Expect.isTrue(asyncReturn is Future); | 104 Expect.isTrue(asyncReturn is Future); |
105 asyncReturn.then((int result) => Expect.equals(result, 27)); | 105 asyncReturn.then((int result) => Expect.equals(result, 27)); |
106 | 106 |
107 var moreNesting = (int shadowP1, String p2, num p3) { | 107 var moreNesting = (int shadowP1, String p2, num p3) { |
108 var z = 3; | 108 var z = 3; |
109 aa(int shadowP1) async { | 109 aa(int shadowP1) async { |
110 return foo + z + p3 + shadowP1; | 110 return foo + z + p3 + shadowP1; |
111 } | 111 } |
112 return aa(6); | 112 return aa(6); |
113 }; | 113 }; |
114 asyncReturn = moreNesting(1, "ignore", 2); | 114 asyncReturn = moreNesting(1, "ignore", 2); |
115 Expect.isTrue(asyncReturn is Future); | 115 Expect.isTrue(asyncReturn is Future); |
116 asyncReturn.then((int result) => Expect.equals(result, 28)); | 116 asyncReturn.then((int result) => Expect.equals(result, 28)); |
117 | 117 |
118 var b1 = const B.createConst(4); /// constructor4: compile-time error | 118 var b1 = const B.createConst(4); //# constructor4: compile-time error |
119 var b2 = new B(); | 119 var b2 = new B(); |
120 b2.dontDoThat = 4; /// setter1: compile-time error | 120 b2.dontDoThat = 4; //# setter1: compile-time error |
121 | 121 |
122 var checkAsync = (var someFunc) { | 122 var checkAsync = (var someFunc) { |
123 var toTest = someFunc(); | 123 var toTest = someFunc(); |
124 Expect.isTrue(toTest is Future); | 124 Expect.isTrue(toTest is Future); |
125 toTest.then((int result) => Expect.equals(result, 4)); | 125 toTest.then((int result) => Expect.equals(result, 4)); |
126 }; | 126 }; |
127 checkAsync(() async => 4); | 127 checkAsync(() async => 4); |
128 | 128 |
129 new A.fail(); /// constructor2: continued | 129 new A.fail(); //# constructor2: continued |
130 new A.create(); /// constructor3: continued | 130 new A.create(); //# constructor3: continued |
131 } | 131 } |
OLD | NEW |