OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // VMOptions=--enable_type_checks --no_show_internal_names | 4 // VMOptions=--enable_type_checks --no_show_internal_names |
5 // Dart test program testing type checks. | 5 // Dart test program testing type checks. |
| 6 |
6 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
7 | 8 |
| 9 class C { |
| 10 factory C() { |
| 11 return 1; // Implicit result type is 'C', not int. |
| 12 } |
| 13 } |
| 14 |
8 class TypeTest { | 15 class TypeTest { |
9 static test() { | 16 static test() { |
10 int result = 0; | 17 int result = 0; |
11 try { | 18 try { |
12 int i = "hello"; // Throws a TypeError if type checks are enabled. | 19 int i = "hello"; // Throws a TypeError if type checks are enabled. |
13 } on TypeError catch (error) { | 20 } on TypeError catch (error, stacktrace) { |
14 result = 1; | 21 result = 1; |
15 Expect.equals("int", error.dstType); | 22 var msg = error.toString(); |
16 Expect.equals("String", error.srcType); | 23 Expect.isTrue(msg.contains("'int'")); // dstType |
17 Expect.equals("i", error.dstName); | 24 Expect.isTrue(msg.contains("'String'")); // srcType |
18 int pos = error.url.lastIndexOf("/", error.url.length); | 25 Expect.isTrue(msg.contains("'i'")); // dstName |
19 if (pos == -1) { | 26 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:19:15")); |
20 pos = error.url.lastIndexOf("\\", error.url.length); | |
21 } | |
22 String subs = error.url.substring(pos + 1, error.url.length); | |
23 Expect.equals("type_vm_test.dart", subs); | |
24 Expect.equals(12, error.line); | |
25 Expect.equals(15, error.column); | |
26 } | 27 } |
27 return result; | 28 return result; |
28 } | 29 } |
29 | 30 |
30 static testSideEffect() { | 31 static testSideEffect() { |
31 int result = 0; | 32 int result = 0; |
32 int index() { | 33 int index() { |
33 result++; | 34 result++; |
34 return 0; | 35 return 0; |
35 } | 36 } |
36 try { | 37 try { |
37 List<int> a = new List<int>(1); | 38 List<int> a = new List<int>(1); |
38 a[0] = 0; | 39 a[0] = 0; |
39 a[index()]++; // Type check succeeds, but does not create side effects. | 40 a[index()]++; // Type check succeeds, but does not create side effects. |
40 Expect.equals(1, a[0]); | 41 Expect.equals(1, a[0]); |
41 } on TypeError catch (error) { | 42 } on TypeError catch (error) { |
42 result = 100; | 43 result = 100; |
43 } | 44 } |
44 return result; | 45 return result; |
45 } | 46 } |
46 | 47 |
47 static testArgument() { | 48 static testArgument() { |
48 int result = 0; | 49 int result = 0; |
49 int f(int i) { | 50 int f(int i) { |
50 return i; | 51 return i; |
51 } | 52 } |
52 try { | 53 try { |
53 int i = f("hello"); // Throws a TypeError if type checks are enabled. | 54 int i = f("hello"); // Throws a TypeError if type checks are enabled. |
54 } on TypeError catch (error) { | 55 } on TypeError catch (error, stacktrace) { |
55 result = 1; | 56 result = 1; |
56 Expect.equals("int", error.dstType); | 57 var msg = error.toString(); |
57 Expect.equals("String", error.srcType); | 58 Expect.isTrue(msg.contains("'int'")); // dstType |
58 Expect.equals("i", error.dstName); | 59 Expect.isTrue(msg.contains("'String'")); // srcType |
59 int pos = error.url.lastIndexOf("/", error.url.length); | 60 Expect.isTrue(msg.contains("'i'")); // dstName |
60 if (pos == -1) { | 61 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:50:15")); |
61 pos = error.url.lastIndexOf("\\", error.url.length); | |
62 } | |
63 String subs = error.url.substring(pos + 1, error.url.length); | |
64 Expect.equals("type_vm_test.dart", subs); | |
65 Expect.equals(49, error.line); | |
66 Expect.equals(15, error.column); | |
67 } | 62 } |
68 return result; | 63 return result; |
69 } | 64 } |
70 | 65 |
71 static testReturn() { | 66 static testReturn() { |
72 int result = 0; | 67 int result = 0; |
73 int f(String s) { | 68 int f(String s) { |
74 return s; | 69 return s; |
75 } | 70 } |
76 try { | 71 try { |
77 int i = f("hello"); // Throws a TypeError if type checks are enabled. | 72 int i = f("hello"); // Throws a TypeError if type checks are enabled. |
78 } on TypeError catch (error) { | 73 } on TypeError catch (error, stacktrace) { |
79 result = 1; | 74 result = 1; |
80 Expect.equals("int", error.dstType); | 75 var msg = error.toString(); |
81 Expect.equals("String", error.srcType); | 76 Expect.isTrue(msg.contains("'int'")); // dstType |
82 Expect.equals("function result", error.dstName); | 77 Expect.isTrue(msg.contains("'String'")); // srcType |
83 int pos = error.url.lastIndexOf("/", error.url.length); | 78 Expect.isTrue(msg.contains("function result")); // dstName |
84 if (pos == -1) { | 79 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:69:14")); |
85 pos = error.url.lastIndexOf("\\", error.url.length); | |
86 } | |
87 String subs = error.url.substring(pos + 1, error.url.length); | |
88 Expect.equals("type_vm_test.dart", subs); | |
89 Expect.equals(74, error.line); | |
90 Expect.equals(14, error.column); | |
91 } | 80 } |
92 return result; | 81 return result; |
93 } | 82 } |
94 | 83 |
95 static int field; | 84 static int field; |
96 static testField() { | 85 static testField() { |
97 int result = 0; | 86 int result = 0; |
98 try { | 87 try { |
99 field = "hello"; // Throws a TypeError if type checks are enabled. | 88 field = "hello"; // Throws a TypeError if type checks are enabled. |
100 } on TypeError catch (error) { | 89 } on TypeError catch (error, stacktrace) { |
101 result = 1; | 90 result = 1; |
102 Expect.equals("int", error.dstType); | 91 var msg = error.toString(); |
103 Expect.equals("String", error.srcType); | 92 Expect.isTrue(msg.contains("'int'")); // dstType |
104 Expect.equals("field", error.dstName); | 93 Expect.isTrue(msg.contains("'String'")); // srcType |
105 int pos = error.url.lastIndexOf("/", error.url.length); | 94 Expect.isTrue(msg.contains("'field'")); // dstName |
106 if (pos == -1) { | 95 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:88:15")); |
107 pos = error.url.lastIndexOf("\\", error.url.length); | |
108 } | |
109 String subs = error.url.substring(pos + 1, error.url.length); | |
110 Expect.equals("type_vm_test.dart", subs); | |
111 Expect.equals(99, error.line); | |
112 Expect.equals(15, error.column); | |
113 } | 96 } |
114 return result; | 97 return result; |
115 } | 98 } |
116 | 99 |
117 static testAnyFunction() { | 100 static testAnyFunction() { |
118 int result = 0; | 101 int result = 0; |
119 Function anyFunction; | 102 Function anyFunction; |
120 f() { }; | 103 f() { }; |
121 anyFunction = f; // No error. | 104 anyFunction = f; // No error. |
122 try { | 105 try { |
123 int i = f; // Throws a TypeError if type checks are enabled. | 106 int i = f; // Throws a TypeError if type checks are enabled. |
124 } on TypeError catch (error) { | 107 } on TypeError catch (error, stacktrace) { |
125 result = 1; | 108 result = 1; |
126 Expect.equals("int", error.dstType); | 109 var msg = error.toString(); |
127 Expect.equals("() => dynamic", error.srcType); | 110 Expect.isTrue(msg.contains("'int'")); // dstType |
128 Expect.equals("i", error.dstName); | 111 Expect.isTrue(msg.contains("'() => dynamic'")); // srcType |
129 int pos = error.url.lastIndexOf("/", error.url.length); | 112 Expect.isTrue(msg.contains("'i'")); // dstName |
130 if (pos == -1) { | 113 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:106:15")); |
131 pos = error.url.lastIndexOf("\\", error.url.length); | |
132 } | |
133 String subs = error.url.substring(pos + 1, error.url.length); | |
134 Expect.equals("type_vm_test.dart", subs); | |
135 Expect.equals(123, error.line); | |
136 Expect.equals(15, error.column); | |
137 } | 114 } |
138 return result; | 115 return result; |
139 } | 116 } |
140 | 117 |
141 static testVoidFunction() { | 118 static testVoidFunction() { |
142 int result = 0; | 119 int result = 0; |
143 Function anyFunction; | 120 Function anyFunction; |
144 void acceptVoidFunObj(void voidFunObj(Object obj)) { }; | 121 void acceptVoidFunObj(void voidFunObj(Object obj)) { }; |
145 void acceptObjFunObj(Object objFunObj(Object obj)) { }; | 122 void acceptObjFunObj(Object objFunObj(Object obj)) { }; |
146 void voidFunObj(Object obj) { }; | 123 void voidFunObj(Object obj) { }; |
147 Object objFunObj(Object obj) { return obj; }; | 124 Object objFunObj(Object obj) { return obj; }; |
148 anyFunction = voidFunObj; // No error. | 125 anyFunction = voidFunObj; // No error. |
149 anyFunction = objFunObj; // No error. | 126 anyFunction = objFunObj; // No error. |
150 acceptVoidFunObj(voidFunObj); | 127 acceptVoidFunObj(voidFunObj); |
151 acceptVoidFunObj(objFunObj); | 128 acceptVoidFunObj(objFunObj); |
152 acceptObjFunObj(objFunObj); | 129 acceptObjFunObj(objFunObj); |
153 try { | 130 try { |
154 acceptObjFunObj(voidFunObj); // Throws a TypeError. | 131 acceptObjFunObj(voidFunObj); // Throws a TypeError. |
155 } on TypeError catch (error) { | 132 } on TypeError catch (error, stacktrace) { |
156 result = 1; | 133 result = 1; |
157 Expect.equals("(Object) => Object", error.dstType); | 134 var msg = error.toString(); |
158 Expect.equals("(Object) => void", error.srcType); | 135 Expect.isTrue(msg.contains("'(Object) => Object'")); // dstType |
159 Expect.equals("objFunObj", error.dstName); | 136 Expect.isTrue(msg.contains("'(Object) => void'")); // srcType |
160 int pos = error.url.lastIndexOf("/", error.url.length); | 137 Expect.isTrue(msg.contains("'objFunObj'")); // dstName |
161 if (pos == -1) { | 138 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:122:33")); |
162 pos = error.url.lastIndexOf("\\", error.url.length); | |
163 } | |
164 String subs = error.url.substring(pos + 1, error.url.length); | |
165 Expect.equals("type_vm_test.dart", subs); | |
166 Expect.equals(145, error.line); | |
167 Expect.equals(33, error.column); | |
168 } | 139 } |
169 return result; | 140 return result; |
170 } | 141 } |
171 | 142 |
172 static testFunctionNum() { | 143 static testFunctionNum() { |
173 int result = 0; | 144 int result = 0; |
174 Function anyFunction; | 145 Function anyFunction; |
175 void acceptFunNum(void funNum(num n)) { }; | 146 void acceptFunNum(void funNum(num n)) { }; |
176 void funObj(Object obj) { }; | 147 void funObj(Object obj) { }; |
177 void funNum(num n) { }; | 148 void funNum(num n) { }; |
178 void funInt(int i) { }; | 149 void funInt(int i) { }; |
179 void funString(String s) { }; | 150 void funString(String s) { }; |
180 anyFunction = funObj; // No error. | 151 anyFunction = funObj; // No error. |
181 anyFunction = funNum; // No error. | 152 anyFunction = funNum; // No error. |
182 anyFunction = funInt; // No error. | 153 anyFunction = funInt; // No error. |
183 anyFunction = funString; // No error. | 154 anyFunction = funString; // No error. |
184 acceptFunNum(funObj); // No error. | 155 acceptFunNum(funObj); // No error. |
185 acceptFunNum(funNum); // No error. | 156 acceptFunNum(funNum); // No error. |
186 acceptFunNum(funInt); // No error. | 157 acceptFunNum(funInt); // No error. |
187 try { | 158 try { |
188 acceptFunNum(funString); // Throws an error. | 159 acceptFunNum(funString); // Throws an error. |
189 } on TypeError catch (error) { | 160 } on TypeError catch (error, stacktrace) { |
190 result = 1; | 161 result = 1; |
191 Expect.equals("(num) => void", error.dstType); | 162 var msg = error.toString(); |
192 Expect.equals("(String) => void", error.srcType); | 163 Expect.isTrue(msg.contains("'(num) => void'")); // dstType |
193 Expect.equals("funNum", error.dstName); | 164 Expect.isTrue(msg.contains("'(String) => void'")); // srcType |
194 int pos = error.url.lastIndexOf("/", error.url.length); | 165 Expect.isTrue(msg.contains("'funNum'")); // dstName |
195 if (pos == -1) { | 166 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:146:28")); |
196 pos = error.url.lastIndexOf("\\", error.url.length); | |
197 } | |
198 String subs = error.url.substring(pos + 1, error.url.length); | |
199 Expect.equals("type_vm_test.dart", subs); | |
200 Expect.equals(175, error.line); | |
201 Expect.equals(28, error.column); | |
202 } | 167 } |
203 return result; | 168 return result; |
204 } | 169 } |
205 | 170 |
206 static testBoolCheck() { | 171 static testBoolCheck() { |
207 int result = 0; | 172 int result = 0; |
208 try { | 173 try { |
209 bool i = !"hello"; // Throws a TypeError if type checks are enabled. | 174 bool i = !"hello"; // Throws a TypeError if type checks are enabled. |
210 } on TypeError catch (error) { | 175 } on TypeError catch (error, stacktrace) { |
211 result++; | 176 result++; |
212 Expect.equals("bool", error.dstType); | 177 var msg = error.toString(); |
213 Expect.equals("String", error.srcType); | 178 Expect.isTrue(msg.contains("'bool'")); // dstType |
214 Expect.equals("boolean expression", error.dstName); | 179 Expect.isTrue(msg.contains("'String'")); // srcType |
215 int pos = error.url.lastIndexOf("/", error.url.length); | 180 Expect.isTrue(msg.contains("boolean expression")); // dstName |
216 if (pos == -1) { | 181 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:174:17")); |
217 pos = error.url.lastIndexOf("\\", error.url.length); | |
218 } | |
219 String subs = error.url.substring(pos + 1, error.url.length); | |
220 Expect.equals("type_vm_test.dart", subs); | |
221 Expect.equals(209, error.line); | |
222 Expect.equals(17, error.column); | |
223 } | 182 } |
224 try { | 183 try { |
225 while ("hello") {}; // Throws a TypeError if type checks are enabled. | 184 while ("hello") {}; // Throws a TypeError if type checks are enabled. |
226 } on TypeError catch (error) { | 185 } on TypeError catch (error, stacktrace) { |
227 result++; | 186 result++; |
228 Expect.equals("bool", error.dstType); | 187 var msg = error.toString(); |
229 Expect.equals("String", error.srcType); | 188 Expect.isTrue(msg.contains("'bool'")); // dstType |
230 Expect.equals("boolean expression", error.dstName); | 189 Expect.isTrue(msg.contains("'String'")); // srcType |
231 int pos = error.url.lastIndexOf("/", error.url.length); | 190 Expect.isTrue(msg.contains("boolean expression")); // dstName |
232 if (pos == -1) { | 191 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:184:14")); |
233 pos = error.url.lastIndexOf("\\", error.url.length); | |
234 } | |
235 String subs = error.url.substring(pos + 1, error.url.length); | |
236 Expect.equals("type_vm_test.dart", subs); | |
237 Expect.equals(225, error.line); | |
238 Expect.equals(14, error.column); | |
239 } | 192 } |
240 try { | 193 try { |
241 do {} while ("hello"); // Throws a TypeError if type checks are enabled. | 194 do {} while ("hello"); // Throws a TypeError if type checks are enabled. |
242 } on TypeError catch (error) { | 195 } on TypeError catch (error, stacktrace) { |
243 result++; | 196 result++; |
244 Expect.equals("bool", error.dstType); | 197 var msg = error.toString(); |
245 Expect.equals("String", error.srcType); | 198 Expect.isTrue(msg.contains("'bool'")); // dstType |
246 Expect.equals("boolean expression", error.dstName); | 199 Expect.isTrue(msg.contains("'String'")); // srcType |
247 int pos = error.url.lastIndexOf("/", error.url.length); | 200 Expect.isTrue(msg.contains("boolean expression")); // dstName |
248 if (pos == -1) { | 201 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:194:20")); |
249 pos = error.url.lastIndexOf("\\", error.url.length); | |
250 } | |
251 String subs = error.url.substring(pos + 1, error.url.length); | |
252 Expect.equals("type_vm_test.dart", subs); | |
253 Expect.equals(241, error.line); | |
254 Expect.equals(20, error.column); | |
255 } | 202 } |
256 try { | 203 try { |
257 for (;"hello";) {}; // Throws a TypeError if type checks are enabled. | 204 for (;"hello";) {}; // Throws a TypeError if type checks are enabled. |
258 } on TypeError catch (error) { | 205 } on TypeError catch (error, stacktrace) { |
259 result++; | 206 result++; |
260 Expect.equals("bool", error.dstType); | 207 var msg = error.toString(); |
261 Expect.equals("String", error.srcType); | 208 Expect.isTrue(msg.contains("'bool'")); // dstType |
262 Expect.equals("boolean expression", error.dstName); | 209 Expect.isTrue(msg.contains("'String'")); // srcType |
263 int pos = error.url.lastIndexOf("/", error.url.length); | 210 Expect.isTrue(msg.contains("boolean expression")); // dstName |
264 if (pos == -1) { | 211 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:204:13")); |
265 pos = error.url.lastIndexOf("\\", error.url.length); | |
266 } | |
267 String subs = error.url.substring(pos + 1, error.url.length); | |
268 Expect.equals("type_vm_test.dart", subs); | |
269 Expect.equals(257, error.line); | |
270 Expect.equals(13, error.column); | |
271 } | 212 } |
272 try { | 213 try { |
273 int i = "hello" ? 1 : 0; // Throws a TypeError if type checks are enabled
. | 214 int i = "hello" ? 1 : 0; // Throws a TypeError if type checks are enabled
. |
274 } on TypeError catch (error) { | 215 } on TypeError catch (error, stacktrace) { |
275 result++; | 216 result++; |
276 Expect.equals("bool", error.dstType); | 217 var msg = error.toString(); |
277 Expect.equals("String", error.srcType); | 218 Expect.isTrue(msg.contains("'bool'")); // dstType |
278 Expect.equals("boolean expression", error.dstName); | 219 Expect.isTrue(msg.contains("'String'")); // srcType |
279 int pos = error.url.lastIndexOf("/", error.url.length); | 220 Expect.isTrue(msg.contains("boolean expression")); // dstName |
280 if (pos == -1) { | 221 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:214:15")); |
281 pos = error.url.lastIndexOf("\\", error.url.length); | |
282 } | |
283 String subs = error.url.substring(pos + 1, error.url.length); | |
284 Expect.equals("type_vm_test.dart", subs); | |
285 Expect.equals(273, error.line); | |
286 Expect.equals(15, error.column); | |
287 } | 222 } |
288 try { | 223 try { |
289 if ("hello") {}; // Throws a TypeError if type checks are enabled. | 224 if ("hello") {}; // Throws a TypeError if type checks are enabled. |
290 } on TypeError catch (error) { | 225 } on TypeError catch (error, stacktrace) { |
291 result++; | 226 result++; |
292 Expect.equals("bool", error.dstType); | 227 var msg = error.toString(); |
293 Expect.equals("String", error.srcType); | 228 Expect.isTrue(msg.contains("'bool'")); // dstType |
294 Expect.equals("boolean expression", error.dstName); | 229 Expect.isTrue(msg.contains("'String'")); // srcType |
295 int pos = error.url.lastIndexOf("/", error.url.length); | 230 Expect.isTrue(msg.contains("boolean expression")); // dstName |
296 if (pos == -1) { | 231 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:224:11")); |
297 pos = error.url.lastIndexOf("\\", error.url.length); | |
298 } | |
299 String subs = error.url.substring(pos + 1, error.url.length); | |
300 Expect.equals("type_vm_test.dart", subs); | |
301 Expect.equals(289, error.line); | |
302 Expect.equals(11, error.column); | |
303 } | 232 } |
304 try { | 233 try { |
305 if ("hello" || false) {}; // Throws a TypeError if type checks are enable
d. | 234 if ("hello" || false) {}; // Throws a TypeError if type checks are enable
d. |
306 } on TypeError catch (error) { | 235 } on TypeError catch (error, stacktrace) { |
307 result++; | 236 result++; |
308 Expect.equals("bool", error.dstType); | 237 var msg = error.toString(); |
309 Expect.equals("String", error.srcType); | 238 Expect.isTrue(msg.contains("'bool'")); // dstType |
310 Expect.equals("boolean expression", error.dstName); | 239 Expect.isTrue(msg.contains("'String'")); // srcType |
311 int pos = error.url.lastIndexOf("/", error.url.length); | 240 Expect.isTrue(msg.contains("boolean expression")); // dstName |
312 if (pos == -1) { | 241 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:234:11")); |
313 pos = error.url.lastIndexOf("\\", error.url.length); | |
314 } | |
315 String subs = error.url.substring(pos + 1, error.url.length); | |
316 Expect.equals("type_vm_test.dart", subs); | |
317 Expect.equals(305, error.line); | |
318 Expect.equals(11, error.column); | |
319 } | 242 } |
320 try { | 243 try { |
321 if (false || "hello") {}; // Throws a TypeError if type checks are enable
d. | 244 if (false || "hello") {}; // Throws a TypeError if type checks are enable
d. |
322 } on TypeError catch (error) { | 245 } on TypeError catch (error, stacktrace) { |
323 result++; | 246 result++; |
324 Expect.equals("bool", error.dstType); | 247 var msg = error.toString(); |
325 Expect.equals("String", error.srcType); | 248 Expect.isTrue(msg.contains("'bool'")); // dstType |
326 Expect.equals("boolean expression", error.dstName); | 249 Expect.isTrue(msg.contains("'String'")); // srcType |
327 int pos = error.url.lastIndexOf("/", error.url.length); | 250 Expect.isTrue(msg.contains("boolean expression")); // dstName |
328 if (pos == -1) { | 251 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:244:20")); |
329 pos = error.url.lastIndexOf("\\", error.url.length); | |
330 } | |
331 String subs = error.url.substring(pos + 1, error.url.length); | |
332 Expect.equals("type_vm_test.dart", subs); | |
333 Expect.equals(321, error.line); | |
334 Expect.equals(20, error.column); | |
335 } | 252 } |
336 try { | 253 try { |
337 if (null) {}; // Throws a TypeError if type checks are enabled. | 254 if (null) {}; // Throws a TypeError if type checks are enabled. |
338 } on TypeError catch (error) { | 255 } on TypeError catch (error, stacktrace) { |
339 result++; | 256 result++; |
340 Expect.equals("bool", error.dstType); | 257 var msg = error.toString(); |
341 Expect.equals("Null", error.srcType); | 258 Expect.isTrue(msg.contains("'bool'")); // dstType |
342 Expect.equals("boolean expression", error.dstName); | 259 Expect.isTrue(msg.contains("'Null'")); // srcType |
343 int pos = error.url.lastIndexOf("/", error.url.length); | 260 Expect.isTrue(msg.contains("boolean expression")); // dstName |
344 if (pos == -1) { | 261 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:254:11")); |
345 pos = error.url.lastIndexOf("\\", error.url.length); | |
346 } | |
347 String subs = error.url.substring(pos + 1, error.url.length); | |
348 Expect.equals("type_vm_test.dart", subs); | |
349 Expect.equals(337, error.line); | |
350 Expect.equals(11, error.column); | |
351 } | 262 } |
352 return result; | 263 return result; |
353 } | 264 } |
354 | 265 |
355 | 266 |
356 static int testFactory() { | 267 static int testFactory() { |
357 int result = 0; | 268 int result = 0; |
358 try { | 269 try { |
359 var x = new C(); | 270 var x = new C(); |
360 } on TypeError catch (error) { | 271 } on TypeError catch (error, stacktrace) { |
361 result++; | 272 result++; |
362 Expect.equals("C", error.dstType); | 273 var msg = error.toString(); |
363 Expect.equals("int", error.srcType); | 274 Expect.isTrue(msg.contains("'C'")); // dstType |
364 Expect.equals("function result", error.dstName); | 275 Expect.isTrue(msg.contains("'int'")); // srcType |
365 int pos = error.url.lastIndexOf("/", error.url.length); | 276 Expect.isTrue(msg.contains("function result")); // dstName |
366 if (pos == -1) { | 277 Expect.isTrue(stacktrace.toString().contains("type_vm_test.dart:11:12")); |
367 pos = error.url.lastIndexOf("\\", error.url.length); | |
368 } | |
369 String subs = error.url.substring(pos + 1, error.url.length); | |
370 Expect.equals("type_vm_test.dart", subs); | |
371 Expect.equals(560, error.line); | |
372 Expect.equals(12, error.column); | |
373 } | 278 } |
374 return result; | 279 return result; |
375 } | 280 } |
376 | 281 |
377 static int testListAssigment() { | 282 static int testListAssigment() { |
378 int result = 0; | 283 int result = 0; |
379 { | 284 { |
380 var a = new List(5); | 285 var a = new List(5); |
381 List a0 = a; | 286 List a0 = a; |
382 List<Object> ao = a; | 287 List<Object> ao = a; |
383 List<int> ai = a; | 288 List<int> ai = a; |
384 List<num> an = a; | 289 List<num> an = a; |
385 List<String> as = a; | 290 List<String> as = a; |
386 } | 291 } |
387 { | 292 { |
388 var a = new List<Object>(5); | 293 var a = new List<Object>(5); |
389 List a0 = a; | 294 List a0 = a; |
390 List<Object> ao = a; | 295 List<Object> ao = a; |
391 try { | 296 try { |
392 List<int> ai = a; | 297 List<int> ai = a; |
393 } on TypeError catch (error) { | 298 } on TypeError catch (error, stacktrace) { |
394 result++; | 299 result++; |
395 Expect.equals("List<int>", error.dstType); | 300 var msg = error.toString(); |
396 Expect.equals("List<Object>", error.srcType); | 301 Expect.isTrue(msg.contains("'List<int>'")); // dstType |
397 Expect.equals("ai", error.dstName); | 302 Expect.isTrue(msg.contains("'List<Object>'")); // srcType |
398 int pos = error.url.lastIndexOf("/", error.url.length); | 303 Expect.isTrue(msg.contains("'ai'")); // dstName |
399 if (pos == -1) { | 304 Expect.isTrue( |
400 pos = error.url.lastIndexOf("\\", error.url.length); | 305 stacktrace.toString().contains("type_vm_test.dart:297:24")); |
401 } | |
402 String subs = error.url.substring(pos + 1, error.url.length); | |
403 Expect.equals("type_vm_test.dart", subs); | |
404 Expect.equals(392, error.line); | |
405 Expect.equals(24, error.column); | |
406 } | 306 } |
407 try { | 307 try { |
408 List<num> an = a; | 308 List<num> an = a; |
409 } on TypeError catch (error) { | 309 } on TypeError catch (error, stacktrace) { |
410 result++; | 310 result++; |
411 Expect.equals("List<num>", error.dstType); | 311 var msg = error.toString(); |
412 Expect.equals("List<Object>", error.srcType); | 312 Expect.isTrue(msg.contains("'List<num>'")); // dstType |
413 Expect.equals("an", error.dstName); | 313 Expect.isTrue(msg.contains("'List<Object>'")); // srcType |
414 int pos = error.url.lastIndexOf("/", error.url.length); | 314 Expect.isTrue(msg.contains("'an'")); // dstName |
415 if (pos == -1) { | 315 Expect.isTrue( |
416 pos = error.url.lastIndexOf("\\", error.url.length); | 316 stacktrace.toString().contains("type_vm_test.dart:308:24")); |
417 } | |
418 String subs = error.url.substring(pos + 1, error.url.length); | |
419 Expect.equals("type_vm_test.dart", subs); | |
420 Expect.equals(408, error.line); | |
421 Expect.equals(24, error.column); | |
422 } | 317 } |
423 try { | 318 try { |
424 List<String> as = a; | 319 List<String> as = a; |
425 } on TypeError catch (error) { | 320 } on TypeError catch (error, stacktrace) { |
426 result++; | 321 result++; |
427 Expect.equals("List<String>", error.dstType); | 322 var msg = error.toString(); |
428 Expect.equals("List<Object>", error.srcType); | 323 Expect.isTrue(msg.contains("'List<String>'")); // dstType |
429 Expect.equals("as", error.dstName); | 324 Expect.isTrue(msg.contains("'List<Object>'")); // srcType |
430 int pos = error.url.lastIndexOf("/", error.url.length); | 325 Expect.isTrue(msg.contains("'as'")); // dstName |
431 if (pos == -1) { | 326 Expect.isTrue( |
432 pos = error.url.lastIndexOf("\\", error.url.length); | 327 stacktrace.toString().contains("type_vm_test.dart:319:27")); |
433 } | |
434 String subs = error.url.substring(pos + 1, error.url.length); | |
435 Expect.equals("type_vm_test.dart", subs); | |
436 Expect.equals(424, error.line); | |
437 Expect.equals(27, error.column); | |
438 } | 328 } |
439 } | 329 } |
440 { | 330 { |
441 var a = new List<int>(5); | 331 var a = new List<int>(5); |
442 List a0 = a; | 332 List a0 = a; |
443 List<Object> ao = a; | 333 List<Object> ao = a; |
444 List<int> ai = a; | 334 List<int> ai = a; |
445 List<num> an = a; | 335 List<num> an = a; |
446 try { | 336 try { |
447 List<String> as = a; | 337 List<String> as = a; |
448 } on TypeError catch (error) { | 338 } on TypeError catch (error, stacktrace) { |
449 result++; | 339 result++; |
450 Expect.equals("List<String>", error.dstType); | 340 var msg = error.toString(); |
451 Expect.equals("List<int>", error.srcType); | 341 Expect.isTrue(msg.contains("'List<String>'")); // dstType |
452 Expect.equals("as", error.dstName); | 342 Expect.isTrue(msg.contains("'List<int>'")); // srcType |
453 int pos = error.url.lastIndexOf("/", error.url.length); | 343 Expect.isTrue(msg.contains("'as'")); // dstName |
454 if (pos == -1) { | 344 Expect.isTrue( |
455 pos = error.url.lastIndexOf("\\", error.url.length); | 345 stacktrace.toString().contains("type_vm_test.dart:337:27")); |
456 } | |
457 String subs = error.url.substring(pos + 1, error.url.length); | |
458 Expect.equals("type_vm_test.dart", subs); | |
459 Expect.equals(447, error.line); | |
460 Expect.equals(27, error.column); | |
461 } | 346 } |
462 } | 347 } |
463 { | 348 { |
464 var a = new List<num>(5); | 349 var a = new List<num>(5); |
465 List a0 = a; | 350 List a0 = a; |
466 List<Object> ao = a; | 351 List<Object> ao = a; |
467 try { | 352 try { |
468 List<int> ai = a; | 353 List<int> ai = a; |
469 } on TypeError catch (error) { | 354 } on TypeError catch (error, stacktrace) { |
470 result++; | 355 result++; |
471 Expect.equals("List<int>", error.dstType); | 356 var msg = error.toString(); |
472 Expect.equals("List<num>", error.srcType); | 357 Expect.isTrue(msg.contains("'List<int>'")); // dstType |
473 Expect.equals("ai", error.dstName); | 358 Expect.isTrue(msg.contains("'List<num>'")); // srcType |
474 int pos = error.url.lastIndexOf("/", error.url.length); | 359 Expect.isTrue(msg.contains("'ai'")); // dstName |
475 if (pos == -1) { | 360 Expect.isTrue( |
476 pos = error.url.lastIndexOf("\\", error.url.length); | 361 stacktrace.toString().contains("type_vm_test.dart:353:24")); |
477 } | |
478 String subs = error.url.substring(pos + 1, error.url.length); | |
479 Expect.equals("type_vm_test.dart", subs); | |
480 Expect.equals(468, error.line); | |
481 Expect.equals(24, error.column); | |
482 } | 362 } |
483 List<num> an = a; | 363 List<num> an = a; |
484 try { | 364 try { |
485 List<String> as = a; | 365 List<String> as = a; |
486 } on TypeError catch (error) { | 366 } on TypeError catch (error, stacktrace) { |
487 result++; | 367 result++; |
488 Expect.equals("List<String>", error.dstType); | 368 var msg = error.toString(); |
489 Expect.equals("List<num>", error.srcType); | 369 Expect.isTrue(msg.contains("'List<String>'")); // dstType |
490 Expect.equals("as", error.dstName); | 370 Expect.isTrue(msg.contains("'List<num>'")); // srcType |
491 int pos = error.url.lastIndexOf("/", error.url.length); | 371 Expect.isTrue(msg.contains("'as'")); // dstName |
492 if (pos == -1) { | 372 Expect.isTrue( |
493 pos = error.url.lastIndexOf("\\", error.url.length); | 373 stacktrace.toString().contains("type_vm_test.dart:365:27")); |
494 } | |
495 String subs = error.url.substring(pos + 1, error.url.length); | |
496 Expect.equals("type_vm_test.dart", subs); | |
497 Expect.equals(485, error.line); | |
498 Expect.equals(27, error.column); | |
499 } | 374 } |
500 } | 375 } |
501 { | 376 { |
502 var a = new List<String>(5); | 377 var a = new List<String>(5); |
503 List a0 = a; | 378 List a0 = a; |
504 List<Object> ao = a; | 379 List<Object> ao = a; |
505 try { | 380 try { |
506 List<int> ai = a; | 381 List<int> ai = a; |
507 } on TypeError catch (error) { | 382 } on TypeError catch (error, stacktrace) { |
508 result++; | 383 result++; |
509 Expect.equals("List<int>", error.dstType); | 384 var msg = error.toString(); |
510 Expect.equals("List<String>", error.srcType); | 385 Expect.isTrue(msg.contains("'List<int>'")); // dstType |
511 Expect.equals("ai", error.dstName); | 386 Expect.isTrue(msg.contains("'List<String>'")); // srcType |
512 int pos = error.url.lastIndexOf("/", error.url.length); | 387 Expect.isTrue(msg.contains("'ai'")); // dstName |
513 if (pos == -1) { | 388 Expect.isTrue( |
514 pos = error.url.lastIndexOf("\\", error.url.length); | 389 stacktrace.toString().contains("type_vm_test.dart:381:24")); |
515 } | |
516 String subs = error.url.substring(pos + 1, error.url.length); | |
517 Expect.equals("type_vm_test.dart", subs); | |
518 Expect.equals(506, error.line); | |
519 Expect.equals(24, error.column); | |
520 } | 390 } |
521 try { | 391 try { |
522 List<num> an = a; | 392 List<num> an = a; |
523 } on TypeError catch (error) { | 393 } on TypeError catch (error, stacktrace) { |
524 result++; | 394 result++; |
525 Expect.equals("List<num>", error.dstType); | 395 var msg = error.toString(); |
526 Expect.equals("List<String>", error.srcType); | 396 Expect.isTrue(msg.contains("'List<num>'")); // dstType |
527 Expect.equals("an", error.dstName); | 397 Expect.isTrue(msg.contains("'List<String>'")); // srcType |
528 int pos = error.url.lastIndexOf("/", error.url.length); | 398 Expect.isTrue(msg.contains("'an'")); // dstName |
529 if (pos == -1) { | 399 Expect.isTrue( |
530 pos = error.url.lastIndexOf("\\", error.url.length); | 400 stacktrace.toString().contains("type_vm_test.dart:392:24")); |
531 } | |
532 String subs = error.url.substring(pos + 1, error.url.length); | |
533 Expect.equals("type_vm_test.dart", subs); | |
534 Expect.equals(522, error.line); | |
535 Expect.equals(24, error.column); | |
536 } | 401 } |
537 List<String> as = a; | 402 List<String> as = a; |
538 } | 403 } |
539 return result; | 404 return result; |
540 } | 405 } |
541 | 406 |
542 static testMain() { | 407 static testMain() { |
543 Expect.equals(1, test()); | 408 Expect.equals(1, test()); |
544 Expect.equals(1, testSideEffect()); | 409 Expect.equals(1, testSideEffect()); |
545 Expect.equals(1, testArgument()); | 410 Expect.equals(1, testArgument()); |
546 Expect.equals(1, testReturn()); | 411 Expect.equals(1, testReturn()); |
547 Expect.equals(1, testField()); | 412 Expect.equals(1, testField()); |
548 Expect.equals(1, testAnyFunction()); | 413 Expect.equals(1, testAnyFunction()); |
549 Expect.equals(1, testVoidFunction()); | 414 Expect.equals(1, testVoidFunction()); |
550 Expect.equals(1, testFunctionNum()); | 415 Expect.equals(1, testFunctionNum()); |
551 Expect.equals(9, testBoolCheck()); | 416 Expect.equals(9, testBoolCheck()); |
552 Expect.equals(1, testFactory()); | 417 Expect.equals(1, testFactory()); |
553 Expect.equals(8, testListAssigment()); | 418 Expect.equals(8, testListAssigment()); |
554 } | 419 } |
555 } | 420 } |
556 | 421 |
557 | |
558 class C { | |
559 factory C() { | |
560 return 1; // Implicit result type is 'C', not int. | |
561 } | |
562 } | |
563 | |
564 | |
565 main() { | 422 main() { |
566 TypeTest.testMain(); | 423 TypeTest.testMain(); |
567 } | 424 } |
OLD | NEW |