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