| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 --enable_asserts | |
| 5 // | 4 // |
| 6 // Dart test program testing type checks. | 5 // Dart test program testing type checks. |
| 7 | 6 |
| 8 class TypeTest { | 7 class TypeTest { |
| 9 static test() { | 8 static test() { |
| 10 int result = 0; | 9 int result = 0; |
| 11 try { | 10 try { |
| 12 int i = "hello"; // Throws a TypeError if type checks are enabled. | 11 // Throws a TypeError if type checks are enabled. |
| 12 int i = "hello"; /// static type warning |
| 13 } catch (TypeError error) { | 13 } catch (TypeError 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 /* | |
| 18 Expect.equals("i", error.dstName); | 17 Expect.equals("i", error.dstName); |
| 19 int pos = error.url.lastIndexOf("/", error.url.length); | 18 int pos = error.url.lastIndexOf("/", error.url.length); |
| 20 if (pos == -1) { | 19 if (pos == -1) { |
| 21 pos = error.url.lastIndexOf("\\", error.url.length); | 20 pos = error.url.lastIndexOf("\\", error.url.length); |
| 22 } | 21 } |
| 23 String subs = error.url.substring(pos + 1, error.url.length); | 22 String subs = error.url.substring(pos + 1, error.url.length); |
| 24 Expect.equals("TypeTest.dart", subs); | 23 Expect.equals("TypeTest.dart", subs); |
| 25 Expect.equals(12, error.line); | 24 Expect.equals(12, error.line); |
| 26 Expect.equals(15, error.column); | 25 Expect.equals(15, error.column); |
| 27 */ | |
| 28 } | 26 } |
| 29 return result; | 27 return result; |
| 30 } | 28 } |
| 31 | 29 |
| 32 static testSideEffect() { | 30 static testSideEffect() { |
| 33 int result = 0; | 31 int result = 0; |
| 34 int index() { | 32 int index() { |
| 35 result++; | 33 result++; |
| 36 return 0; | 34 return 0; |
| 37 } | 35 } |
| 38 try { | 36 try { |
| 39 List<int> a = new List<int>(1); | 37 List<int> a = new List<int>(1); |
| 40 a[0] = 0; | 38 a[0] = 0; |
| 41 a[index()]++; // Type check succeeds, but does not create side effects. | 39 a[index()]++; // Type check succeeds, but does not create side effects. |
| 42 assert(a[0] == 1); | 40 assert(a[0] == 1); |
| 43 } catch (TypeError error) { | 41 } catch (TypeError error) { |
| 44 result = 100; | 42 result = 100; |
| 45 } | 43 } |
| 46 return result; | 44 return result; |
| 47 } | 45 } |
| 48 | 46 |
| 49 static testArgument() { | 47 static testArgument() { |
| 50 int result = 0; | 48 int result = 0; |
| 51 int f(int i) { | 49 int f(int i) { |
| 52 return i; | 50 return i; |
| 53 } | 51 } |
| 54 try { | 52 try { |
| 55 int i = f("hello"); // Throws a TypeError if type checks are enabled. | 53 // Throws a TypeError if type checks are enabled. |
| 54 int i = f("hello"); /// static type warning |
| 56 } catch (TypeError error) { | 55 } catch (TypeError error) { |
| 57 result = 1; | 56 result = 1; |
| 58 Expect.equals("int", error.dstType); | 57 Expect.equals("int", error.dstType); |
| 59 Expect.equals("String", error.srcType); | 58 Expect.equals("String", error.srcType); |
| 60 /* | |
| 61 Expect.equals("i", error.dstName); | 59 Expect.equals("i", error.dstName); |
| 62 int pos = error.url.lastIndexOf("/", error.url.length); | 60 int pos = error.url.lastIndexOf("/", error.url.length); |
| 63 if (pos == -1) { | 61 if (pos == -1) { |
| 64 pos = error.url.lastIndexOf("\\", error.url.length); | 62 pos = error.url.lastIndexOf("\\", error.url.length); |
| 65 } | 63 } |
| 66 String subs = error.url.substring(pos + 1, error.url.length); | 64 String subs = error.url.substring(pos + 1, error.url.length); |
| 67 Expect.equals("TypeTest.dart", subs); | 65 Expect.equals("TypeTest.dart", subs); |
| 68 Expect.equals(49, error.line); | 66 Expect.equals(49, error.line); |
| 69 Expect.equals(15, error.column); | 67 Expect.equals(15, error.column); |
| 70 */ | |
| 71 } | 68 } |
| 72 return result; | 69 return result; |
| 73 } | 70 } |
| 74 | 71 |
| 75 static testReturn() { | 72 static testReturn() { |
| 76 int result = 0; | 73 int result = 0; |
| 77 int f(String s) { | 74 int f(String s) { |
| 78 return s; | 75 // String not assignable to int on return |
| 76 return s; /// static type warning |
| 79 } | 77 } |
| 80 try { | 78 try { |
| 81 int i = f("hello"); // Throws a TypeError if type checks are enabled. | 79 // Throws a TypeError if type checks are enabled. |
| 80 int i = f("hello"); |
| 82 } catch (TypeError error) { | 81 } catch (TypeError error) { |
| 83 result = 1; | 82 result = 1; |
| 84 Expect.equals("int", error.dstType); | 83 Expect.equals("int", error.dstType); |
| 85 Expect.equals("String", error.srcType); | 84 Expect.equals("String", error.srcType); |
| 86 /* | |
| 87 Expect.equals("function result", error.dstName); | 85 Expect.equals("function result", error.dstName); |
| 88 int pos = error.url.lastIndexOf("/", error.url.length); | 86 int pos = error.url.lastIndexOf("/", error.url.length); |
| 89 if (pos == -1) { | 87 if (pos == -1) { |
| 90 pos = error.url.lastIndexOf("\\", error.url.length); | 88 pos = error.url.lastIndexOf("\\", error.url.length); |
| 91 } | 89 } |
| 92 String subs = error.url.substring(pos + 1, error.url.length); | 90 String subs = error.url.substring(pos + 1, error.url.length); |
| 93 Expect.equals("TypeTest.dart", subs); | 91 Expect.equals("TypeTest.dart", subs); |
| 94 Expect.equals(74, error.line); | 92 Expect.equals(74, error.line); |
| 95 Expect.equals(14, error.column); | 93 Expect.equals(14, error.column); |
| 96 */ | |
| 97 } | 94 } |
| 98 return result; | 95 return result; |
| 99 } | 96 } |
| 100 | 97 |
| 101 static int field; | 98 static int field; |
| 102 static testField() { | 99 static testField() { |
| 103 int result = 0; | 100 int result = 0; |
| 104 try { | 101 try { |
| 105 field = "hello"; // Throws a TypeError if type checks are enabled. | 102 // Throws a TypeError if type checks are enabled. |
| 103 field = "hello"; /// static type warning |
| 106 } catch (TypeError error) { | 104 } catch (TypeError error) { |
| 107 result = 1; | 105 result = 1; |
| 108 Expect.equals("int", error.dstType); | 106 Expect.equals("int", error.dstType); |
| 109 Expect.equals("String", error.srcType); | 107 Expect.equals("String", error.srcType); |
| 110 /* | |
| 111 Expect.equals("field", error.dstName); | 108 Expect.equals("field", error.dstName); |
| 112 int pos = error.url.lastIndexOf("/", error.url.length); | 109 int pos = error.url.lastIndexOf("/", error.url.length); |
| 113 if (pos == -1) { | 110 if (pos == -1) { |
| 114 pos = error.url.lastIndexOf("\\", error.url.length); | 111 pos = error.url.lastIndexOf("\\", error.url.length); |
| 115 } | 112 } |
| 116 String subs = error.url.substring(pos + 1, error.url.length); | 113 String subs = error.url.substring(pos + 1, error.url.length); |
| 117 Expect.equals("TypeTest.dart", subs); | 114 Expect.equals("TypeTest.dart", subs); |
| 118 Expect.equals(99, error.line); | 115 Expect.equals(99, error.line); |
| 119 Expect.equals(15, error.column); | 116 Expect.equals(15, error.column); |
| 120 */ | |
| 121 } | 117 } |
| 122 return result; | 118 return result; |
| 123 } | 119 } |
| 124 | 120 |
| 125 static testAnyFunction() { | 121 static testAnyFunction() { |
| 126 int result = 0; | 122 int result = 0; |
| 127 Function anyFunction; | 123 Function anyFunction; |
| 128 f() { }; | 124 f() { }; |
| 129 anyFunction = f; // No error. | 125 anyFunction = f; // No error. |
| 130 try { | 126 try { |
| 131 int i = f; // Throws a TypeError if type checks are enabled. | 127 // Throws a TypeError if type checks are enabled. |
| 128 int i = f; /// static type warning |
| 132 } catch (TypeError error) { | 129 } catch (TypeError error) { |
| 133 result = 1; | 130 result = 1; |
| 134 Expect.equals("int", error.dstType); | 131 Expect.equals("int", error.dstType); |
| 135 /* | 132 Expect.equals("() => var", error.srcType); // TODO(regis): => Dynamic. |
| 136 Expect.equals("() => var", error.srcType); TODO(regis): => Dynamic. | |
| 137 Expect.equals("i", error.dstName); | 133 Expect.equals("i", error.dstName); |
| 138 int pos = error.url.lastIndexOf("/", error.url.length); | 134 int pos = error.url.lastIndexOf("/", error.url.length); |
| 139 if (pos == -1) { | 135 if (pos == -1) { |
| 140 pos = error.url.lastIndexOf("\\", error.url.length); | 136 pos = error.url.lastIndexOf("\\", error.url.length); |
| 141 } | 137 } |
| 142 String subs = error.url.substring(pos + 1, error.url.length); | 138 String subs = error.url.substring(pos + 1, error.url.length); |
| 143 Expect.equals("TypeTest.dart", subs); | 139 Expect.equals("TypeTest.dart", subs); |
| 144 Expect.equals(123, error.line); | 140 Expect.equals(123, error.line); |
| 145 Expect.equals(15, error.column); | 141 Expect.equals(15, error.column); |
| 146 */ | |
| 147 } | 142 } |
| 148 return result; | 143 return result; |
| 149 } | 144 } |
| 150 | 145 |
| 151 static testVoidFunction() { | 146 static testVoidFunction() { |
| 152 int result = 0; | 147 int result = 0; |
| 153 Function anyFunction; | 148 Function anyFunction; |
| 154 void acceptVoidFunObj(void voidFunObj(Object obj)) { }; | 149 void acceptVoidFunObj(void voidFunObj(Object obj)) { }; |
| 155 void acceptObjFunObj(Object objFunObj(Object obj)) { }; | 150 void acceptObjFunObj(Object objFunObj(Object obj)) { }; |
| 156 void voidFunObj(Object obj) { }; | 151 void voidFunObj(Object obj) { }; |
| 157 Object objFunObj(Object obj) { return obj; }; | 152 Object objFunObj(Object obj) { return obj; }; |
| 158 anyFunction = voidFunObj; // No error. | 153 anyFunction = voidFunObj; // No error. |
| 159 anyFunction = objFunObj; // No error. | 154 anyFunction = objFunObj; // No error. |
| 160 acceptVoidFunObj(voidFunObj); | 155 acceptVoidFunObj(voidFunObj); |
| 161 acceptVoidFunObj(objFunObj); | 156 acceptVoidFunObj(objFunObj); |
| 162 acceptObjFunObj(objFunObj); | 157 acceptObjFunObj(objFunObj); |
| 163 try { | 158 try { |
| 164 acceptObjFunObj(voidFunObj); // Throws a TypeError. | 159 // Throws a TypeError. Issue 2348 |
| 160 acceptObjFunObj(voidFunObj); /// static type warning |
| 165 } catch (TypeError error) { | 161 } catch (TypeError error) { |
| 166 result = 1; | 162 result = 1; |
| 167 /* | |
| 168 Expect.equals("(Object) => Object", error.dstType); | 163 Expect.equals("(Object) => Object", error.dstType); |
| 169 Expect.equals("(Object) => void", error.srcType); | 164 Expect.equals("(Object) => void", error.srcType); |
| 170 Expect.equals("objFunObj", error.dstName); | 165 Expect.equals("objFunObj", error.dstName); |
| 171 int pos = error.url.lastIndexOf("/", error.url.length); | 166 int pos = error.url.lastIndexOf("/", error.url.length); |
| 172 if (pos == -1) { | 167 if (pos == -1) { |
| 173 pos = error.url.lastIndexOf("\\", error.url.length); | 168 pos = error.url.lastIndexOf("\\", error.url.length); |
| 174 } | 169 } |
| 175 String subs = error.url.substring(pos + 1, error.url.length); | 170 String subs = error.url.substring(pos + 1, error.url.length); |
| 176 Expect.equals("TypeTest.dart", subs); | 171 Expect.equals("TypeTest.dart", subs); |
| 177 Expect.equals(145, error.line); | 172 Expect.equals(145, error.line); |
| 178 Expect.equals(33, error.column); | 173 Expect.equals(33, error.column); |
| 179 */ | |
| 180 } | 174 } |
| 181 return result; | 175 return result; |
| 182 } | 176 } |
| 183 | 177 |
| 184 static testFunctionNum() { | 178 static testFunctionNum() { |
| 185 int result = 0; | 179 int result = 0; |
| 186 Function anyFunction; | 180 Function anyFunction; |
| 187 void acceptFunNum(void funNum(num num)) { }; | 181 void acceptFunNum(void funNum(num num)) { }; |
| 188 void funObj(Object obj) { }; | 182 void funObj(Object obj) { }; |
| 189 void funNum(num num) { }; | 183 void funNum(num num) { }; |
| 190 void funInt(int i) { }; | 184 void funInt(int i) { }; |
| 191 void funString(String s) { }; | 185 void funString(String s) { }; |
| 192 anyFunction = funObj; // No error. | 186 anyFunction = funObj; // No error. |
| 193 anyFunction = funNum; // No error. | 187 anyFunction = funNum; // No error. |
| 194 anyFunction = funInt; // No error. | 188 anyFunction = funInt; // No error. |
| 195 anyFunction = funString; // No error. | 189 anyFunction = funString; // No error. |
| 196 acceptFunNum(funObj); // No error. | 190 acceptFunNum(funObj); // No error. |
| 197 acceptFunNum(funNum); // No error. | 191 acceptFunNum(funNum); // No error. |
| 198 acceptFunNum(funInt); // No error. | 192 acceptFunNum(funInt); // No error. |
| 199 try { | 193 try { |
| 200 acceptFunNum(funString); // Throws an error. | 194 // Throws an error. |
| 195 acceptFunNum(funString); /// static type warning |
| 201 } catch (TypeError error) { | 196 } catch (TypeError error) { |
| 202 result = 1; | 197 result = 1; |
| 203 /* | |
| 204 Expect.equals("(num) => void", error.dstType); | 198 Expect.equals("(num) => void", error.dstType); |
| 205 Expect.equals("(String) => void", error.srcType); | 199 Expect.equals("(String) => void", error.srcType); |
| 206 Expect.equals("funNum", error.dstName); | 200 Expect.equals("funNum", error.dstName); |
| 207 int pos = error.url.lastIndexOf("/", error.url.length); | 201 int pos = error.url.lastIndexOf("/", error.url.length); |
| 208 if (pos == -1) { | 202 if (pos == -1) { |
| 209 pos = error.url.lastIndexOf("\\", error.url.length); | 203 pos = error.url.lastIndexOf("\\", error.url.length); |
| 210 } | 204 } |
| 211 String subs = error.url.substring(pos + 1, error.url.length); | 205 String subs = error.url.substring(pos + 1, error.url.length); |
| 212 Expect.equals("TypeTest.dart", subs); | 206 Expect.equals("TypeTest.dart", subs); |
| 213 Expect.equals(175, error.line); | 207 Expect.equals(175, error.line); |
| 214 Expect.equals(28, error.column); | 208 Expect.equals(28, error.column); |
| 215 */ | |
| 216 } | 209 } |
| 217 return result; | 210 return result; |
| 218 } | 211 } |
| 219 | 212 |
| 220 static testBoolCheck() { | 213 static testBoolCheck() { |
| 221 int result = 0; | 214 int result = 0; |
| 222 try { | 215 try { |
| 223 bool i = !"hello"; // Throws a TypeError if type checks are enabled. | 216 // Throws a TypeError if type checks are enabled. |
| 217 bool i = !"hello"; /// static type warning |
| 224 } catch (TypeError error) { | 218 } catch (TypeError error) { |
| 225 result++; | 219 result++; |
| 226 Expect.equals("bool", error.dstType); | 220 Expect.equals("bool", error.dstType); |
| 227 Expect.equals("String", error.srcType); | 221 Expect.equals("String", error.srcType); |
| 228 /* | |
| 229 Expect.equals("boolean expression", error.dstName); | 222 Expect.equals("boolean expression", error.dstName); |
| 230 int pos = error.url.lastIndexOf("/", error.url.length); | 223 int pos = error.url.lastIndexOf("/", error.url.length); |
| 231 if (pos == -1) { | 224 if (pos == -1) { |
| 232 pos = error.url.lastIndexOf("\\", error.url.length); | 225 pos = error.url.lastIndexOf("\\", error.url.length); |
| 233 } | 226 } |
| 234 String subs = error.url.substring(pos + 1, error.url.length); | 227 String subs = error.url.substring(pos + 1, error.url.length); |
| 235 Expect.equals("TypeTest.dart", subs); | 228 Expect.equals("TypeTest.dart", subs); |
| 236 Expect.equals(209, error.line); | 229 Expect.equals(209, error.line); |
| 237 Expect.equals(17, error.column); | 230 Expect.equals(17, error.column); |
| 238 */ | |
| 239 } | 231 } |
| 240 try { | 232 try { |
| 241 while ("hello") {}; // Throws a TypeError if type checks are enabled. | 233 // Throws a TypeError if type checks are enabled. |
| 234 while ("hello") {}; /// static type warning |
| 242 } catch (TypeError error) { | 235 } catch (TypeError error) { |
| 243 result++; | 236 result++; |
| 244 Expect.equals("bool", error.dstType); | 237 Expect.equals("bool", error.dstType); |
| 245 Expect.equals("String", error.srcType); | 238 Expect.equals("String", error.srcType); |
| 246 /* | |
| 247 Expect.equals("boolean expression", error.dstName); | 239 Expect.equals("boolean expression", error.dstName); |
| 248 int pos = error.url.lastIndexOf("/", error.url.length); | 240 int pos = error.url.lastIndexOf("/", error.url.length); |
| 249 if (pos == -1) { | 241 if (pos == -1) { |
| 250 pos = error.url.lastIndexOf("\\", error.url.length); | 242 pos = error.url.lastIndexOf("\\", error.url.length); |
| 251 } | 243 } |
| 252 String subs = error.url.substring(pos + 1, error.url.length); | 244 String subs = error.url.substring(pos + 1, error.url.length); |
| 253 Expect.equals("TypeTest.dart", subs); | 245 Expect.equals("TypeTest.dart", subs); |
| 254 Expect.equals(225, error.line); | 246 Expect.equals(225, error.line); |
| 255 Expect.equals(14, error.column); | 247 Expect.equals(14, error.column); |
| 256 */ | |
| 257 } | 248 } |
| 258 try { | 249 try { |
| 259 do {} while ("hello"); // Throws a TypeError if type checks are enabled. | 250 // Throws a TypeError if type checks are enabled. |
| 251 do {} while ("hello"); /// static type warning |
| 260 } catch (TypeError error) { | 252 } catch (TypeError error) { |
| 261 result++; | 253 result++; |
| 262 Expect.equals("bool", error.dstType); | 254 Expect.equals("bool", error.dstType); |
| 263 Expect.equals("String", error.srcType); | 255 Expect.equals("String", error.srcType); |
| 264 /* | |
| 265 Expect.equals("boolean expression", error.dstName); | 256 Expect.equals("boolean expression", error.dstName); |
| 266 int pos = error.url.lastIndexOf("/", error.url.length); | 257 int pos = error.url.lastIndexOf("/", error.url.length); |
| 267 if (pos == -1) { | 258 if (pos == -1) { |
| 268 pos = error.url.lastIndexOf("\\", error.url.length); | 259 pos = error.url.lastIndexOf("\\", error.url.length); |
| 269 } | 260 } |
| 270 String subs = error.url.substring(pos + 1, error.url.length); | 261 String subs = error.url.substring(pos + 1, error.url.length); |
| 271 Expect.equals("TypeTest.dart", subs); | 262 Expect.equals("TypeTest.dart", subs); |
| 272 Expect.equals(241, error.line); | 263 Expect.equals(241, error.line); |
| 273 Expect.equals(20, error.column); | 264 Expect.equals(20, error.column); |
| 274 */ | |
| 275 } | 265 } |
| 276 try { | 266 try { |
| 277 for (;"hello";) {}; // Throws a TypeError if type checks are enabled. | 267 // Throws a TypeError if type checks are enabled. |
| 268 for (;"hello";) {}; /// static type warning |
| 278 } catch (TypeError error) { | 269 } catch (TypeError error) { |
| 279 result++; | 270 result++; |
| 280 Expect.equals("bool", error.dstType); | 271 Expect.equals("bool", error.dstType); |
| 281 Expect.equals("String", error.srcType); | 272 Expect.equals("String", error.srcType); |
| 282 /* | |
| 283 Expect.equals("boolean expression", error.dstName); | 273 Expect.equals("boolean expression", error.dstName); |
| 284 int pos = error.url.lastIndexOf("/", error.url.length); | 274 int pos = error.url.lastIndexOf("/", error.url.length); |
| 285 if (pos == -1) { | 275 if (pos == -1) { |
| 286 pos = error.url.lastIndexOf("\\", error.url.length); | 276 pos = error.url.lastIndexOf("\\", error.url.length); |
| 287 } | 277 } |
| 288 String subs = error.url.substring(pos + 1, error.url.length); | 278 String subs = error.url.substring(pos + 1, error.url.length); |
| 289 Expect.equals("TypeTest.dart", subs); | 279 Expect.equals("TypeTest.dart", subs); |
| 290 Expect.equals(257, error.line); | 280 Expect.equals(257, error.line); |
| 291 Expect.equals(13, error.column); | 281 Expect.equals(13, error.column); |
| 292 */ | |
| 293 } | 282 } |
| 294 try { | 283 try { |
| 295 int i = "hello" ? 1 : 0; // Throws a TypeError if type checks are enabled
. | 284 // Throws a TypeError if type checks are enabled. |
| 285 int i = "hello" ? 1 : 0; /// static type warning |
| 296 } catch (TypeError error) { | 286 } catch (TypeError error) { |
| 297 result++; | 287 result++; |
| 298 Expect.equals("bool", error.dstType); | 288 Expect.equals("bool", error.dstType); |
| 299 Expect.equals("String", error.srcType); | 289 Expect.equals("String", error.srcType); |
| 300 /* | |
| 301 Expect.equals("boolean expression", error.dstName); | 290 Expect.equals("boolean expression", error.dstName); |
| 302 int pos = error.url.lastIndexOf("/", error.url.length); | 291 int pos = error.url.lastIndexOf("/", error.url.length); |
| 303 if (pos == -1) { | 292 if (pos == -1) { |
| 304 pos = error.url.lastIndexOf("\\", error.url.length); | 293 pos = error.url.lastIndexOf("\\", error.url.length); |
| 305 } | 294 } |
| 306 String subs = error.url.substring(pos + 1, error.url.length); | 295 String subs = error.url.substring(pos + 1, error.url.length); |
| 307 Expect.equals("TypeTest.dart", subs); | 296 Expect.equals("TypeTest.dart", subs); |
| 308 Expect.equals(273, error.line); | 297 Expect.equals(273, error.line); |
| 309 Expect.equals(15, error.column); | 298 Expect.equals(15, error.column); |
| 310 */ | |
| 311 } | 299 } |
| 312 try { | 300 try { |
| 313 if ("hello") {}; // Throws a TypeError if type checks are enabled. | 301 // Throws a TypeError if type checks are enabled. |
| 302 if ("hello") {}; /// static type warning |
| 314 } catch (TypeError error) { | 303 } catch (TypeError error) { |
| 315 result++; | 304 result++; |
| 316 Expect.equals("bool", error.dstType); | 305 Expect.equals("bool", error.dstType); |
| 317 Expect.equals("String", error.srcType); | 306 Expect.equals("String", error.srcType); |
| 318 /* | |
| 319 Expect.equals("boolean expression", error.dstName); | 307 Expect.equals("boolean expression", error.dstName); |
| 320 int pos = error.url.lastIndexOf("/", error.url.length); | 308 int pos = error.url.lastIndexOf("/", error.url.length); |
| 321 if (pos == -1) { | 309 if (pos == -1) { |
| 322 pos = error.url.lastIndexOf("\\", error.url.length); | 310 pos = error.url.lastIndexOf("\\", error.url.length); |
| 323 } | 311 } |
| 324 String subs = error.url.substring(pos + 1, error.url.length); | 312 String subs = error.url.substring(pos + 1, error.url.length); |
| 325 Expect.equals("TypeTest.dart", subs); | 313 Expect.equals("TypeTest.dart", subs); |
| 326 Expect.equals(289, error.line); | 314 Expect.equals(289, error.line); |
| 327 Expect.equals(11, error.column); | 315 Expect.equals(11, error.column); |
| 328 */ | |
| 329 } | 316 } |
| 330 try { | 317 try { |
| 331 if ("hello" || false) {}; // Throws a TypeError if type checks are enable
d. | 318 // Throws a TypeError if type checks are enabled. |
| 319 if ("hello" || false) {}; /// static type warning |
| 332 } catch (TypeError error) { | 320 } catch (TypeError error) { |
| 333 result++; | 321 result++; |
| 334 Expect.equals("bool", error.dstType); | 322 Expect.equals("bool", error.dstType); |
| 335 Expect.equals("String", error.srcType); | 323 Expect.equals("String", error.srcType); |
| 336 /* | |
| 337 Expect.equals("boolean expression", error.dstName); | 324 Expect.equals("boolean expression", error.dstName); |
| 338 int pos = error.url.lastIndexOf("/", error.url.length); | 325 int pos = error.url.lastIndexOf("/", error.url.length); |
| 339 if (pos == -1) { | 326 if (pos == -1) { |
| 340 pos = error.url.lastIndexOf("\\", error.url.length); | 327 pos = error.url.lastIndexOf("\\", error.url.length); |
| 341 } | 328 } |
| 342 String subs = error.url.substring(pos + 1, error.url.length); | 329 String subs = error.url.substring(pos + 1, error.url.length); |
| 343 Expect.equals("TypeTest.dart", subs); | 330 Expect.equals("TypeTest.dart", subs); |
| 344 Expect.equals(305, error.line); | 331 Expect.equals(305, error.line); |
| 345 Expect.equals(11, error.column); | 332 Expect.equals(11, error.column); |
| 346 */ | |
| 347 } | 333 } |
| 348 try { | 334 try { |
| 349 if (false || "hello") {}; // Throws a TypeError if type checks are enable
d. | 335 // Throws a TypeError if type checks are enabled. |
| 336 if (false || "hello") {}; /// static type warning |
| 350 } catch (TypeError error) { | 337 } catch (TypeError error) { |
| 351 result++; | 338 result++; |
| 352 Expect.equals("bool", error.dstType); | 339 Expect.equals("bool", error.dstType); |
| 353 Expect.equals("String", error.srcType); | 340 Expect.equals("String", error.srcType); |
| 354 /* | |
| 355 Expect.equals("boolean expression", error.dstName); | 341 Expect.equals("boolean expression", error.dstName); |
| 356 int pos = error.url.lastIndexOf("/", error.url.length); | 342 int pos = error.url.lastIndexOf("/", error.url.length); |
| 357 if (pos == -1) { | 343 if (pos == -1) { |
| 358 pos = error.url.lastIndexOf("\\", error.url.length); | 344 pos = error.url.lastIndexOf("\\", error.url.length); |
| 359 } | 345 } |
| 360 String subs = error.url.substring(pos + 1, error.url.length); | 346 String subs = error.url.substring(pos + 1, error.url.length); |
| 361 Expect.equals("TypeTest.dart", subs); | 347 Expect.equals("TypeTest.dart", subs); |
| 362 Expect.equals(321, error.line); | 348 Expect.equals(321, error.line); |
| 363 Expect.equals(20, error.column); | 349 Expect.equals(20, error.column); |
| 364 */ | |
| 365 } | 350 } |
| 366 try { | 351 try { |
| 367 // TODO: I don't this should throw a TypeError, as null is a valid bool | 352 // TODO: I don't this should throw a TypeError, as null is a valid bool |
| 368 // value. It might well should throw some other exception however. | 353 // value. It might well should throw some other exception however. |
| 369 // if (null) {}; // Throws a TypeError if type checks are enabled. | 354 // if (null) {}; // Throws a TypeError if type checks are enabled. |
| 370 } catch (TypeError error) { | 355 } catch (TypeError error) { |
| 371 result++; | 356 result++; |
| 372 Expect.equals("bool", error.dstType); | 357 Expect.equals("bool", error.dstType); |
| 373 Expect.equals("Null", error.srcType); | 358 Expect.equals("Null", error.srcType); |
| 374 /* | |
| 375 Expect.equals("boolean expression", error.dstName); | 359 Expect.equals("boolean expression", error.dstName); |
| 376 int pos = error.url.lastIndexOf("/", error.url.length); | 360 int pos = error.url.lastIndexOf("/", error.url.length); |
| 377 if (pos == -1) { | 361 if (pos == -1) { |
| 378 pos = error.url.lastIndexOf("\\", error.url.length); | 362 pos = error.url.lastIndexOf("\\", error.url.length); |
| 379 } | 363 } |
| 380 String subs = error.url.substring(pos + 1, error.url.length); | 364 String subs = error.url.substring(pos + 1, error.url.length); |
| 381 Expect.equals("TypeTest.dart", subs); | 365 Expect.equals("TypeTest.dart", subs); |
| 382 Expect.equals(337, error.line); | 366 Expect.equals(337, error.line); |
| 383 Expect.equals(11, error.column); | 367 Expect.equals(11, error.column); |
| 384 */ | |
| 385 } | 368 } |
| 386 return result; | 369 return result; |
| 387 } | 370 } |
| 388 | 371 |
| 389 | 372 |
| 390 static int testFactory() { | 373 static int testFactory() { |
| 391 int result = 0; | 374 int result = 0; |
| 392 try { | 375 try { |
| 393 var x = new C(); | 376 var x = new C(); |
| 394 } catch (TypeError error) { | 377 } catch (TypeError error) { |
| 395 result++; | 378 result++; |
| 396 Expect.equals("C", error.dstType); | 379 Expect.equals("C", error.dstType); |
| 397 Expect.equals("Smi", error.srcType); | 380 Expect.equals("Smi", error.srcType); |
| 398 /* | |
| 399 Expect.equals("function result", error.dstName); | 381 Expect.equals("function result", error.dstName); |
| 400 int pos = error.url.lastIndexOf("/", error.url.length); | 382 int pos = error.url.lastIndexOf("/", error.url.length); |
| 401 if (pos == -1) { | 383 if (pos == -1) { |
| 402 pos = error.url.lastIndexOf("\\", error.url.length); | 384 pos = error.url.lastIndexOf("\\", error.url.length); |
| 403 } | 385 } |
| 404 String subs = error.url.substring(pos + 1, error.url.length); | 386 String subs = error.url.substring(pos + 1, error.url.length); |
| 405 Expect.equals("TypeTest.dart", subs); | 387 Expect.equals("TypeTest.dart", subs); |
| 406 Expect.equals(472, error.line); | 388 Expect.equals(472, error.line); |
| 407 Expect.equals(12, error.column); | 389 Expect.equals(12, error.column); |
| 408 */ | |
| 409 } | 390 } |
| 410 return result; | 391 return result; |
| 411 } | 392 } |
| 412 | 393 |
| 413 static int testListAssigment() { | 394 static int testListAssigment() { |
| 414 int result = 0; | 395 int result = 0; |
| 415 { | 396 { |
| 416 var a = new List(5); | 397 var a = new List(5); |
| 417 List a0 = a; | 398 List a0 = a; |
| 418 List<Object> ao = a; | 399 List<Object> ao = a; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 class C { | 487 class C { |
| 507 factory C() { | 488 factory C() { |
| 508 return 1; // Implicit result type is 'C', not int. | 489 return 1; // Implicit result type is 'C', not int. |
| 509 } | 490 } |
| 510 } | 491 } |
| 511 | 492 |
| 512 | 493 |
| 513 main() { | 494 main() { |
| 514 TypeTest.testMain(); | 495 TypeTest.testMain(); |
| 515 } | 496 } |
| OLD | NEW |