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