| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import | 6 import |
| 7 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' | 7 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' |
| 8 show TypeMask; | 8 show TypeMask; |
| 9 | 9 |
| 10 import 'compiler_helper.dart'; | 10 import 'compiler_helper.dart'; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 returnIntAsNum() { | 229 returnIntAsNum() { |
| 230 return 0 as num; | 230 return 0 as num; |
| 231 } | 231 } |
| 232 | 232 |
| 233 typedef int Foo(); | 233 typedef int Foo(); |
| 234 | 234 |
| 235 returnAsTypedef() { | 235 returnAsTypedef() { |
| 236 return topLevelGetter() as Foo; | 236 return topLevelGetter() as Foo; |
| 237 } | 237 } |
| 238 | 238 |
| 239 testDeadCode() { |
| 240 return 42; |
| 241 return 'foo'; |
| 242 } |
| 243 |
| 244 testLabeledIf(a) { |
| 245 var c; |
| 246 L1: if (a > 1) { |
| 247 if (a == 2) { |
| 248 break L1; |
| 249 } |
| 250 c = 42; |
| 251 } else { |
| 252 c = 38; |
| 253 } |
| 254 return c; |
| 255 } |
| 256 |
| 239 testSwitch1() { | 257 testSwitch1() { |
| 240 var a = null; | 258 var a = null; |
| 241 switch (topLevelGetter) { | 259 switch (topLevelGetter) { |
| 242 case 100: a = 42.5; break; | 260 case 100: a = 42.5; break; |
| 243 case 200: a = 42; break; | 261 case 200: a = 42; break; |
| 244 } | 262 } |
| 245 return a; | 263 return a; |
| 246 } | 264 } |
| 247 | 265 |
| 248 testSwitch2() { | 266 testSwitch2() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 259 testSwitch3() { | 277 testSwitch3() { |
| 260 var a = 42; | 278 var a = 42; |
| 261 var b; | 279 var b; |
| 262 switch (topLevelGetter) { | 280 switch (topLevelGetter) { |
| 263 L1: case 1: b = a + 42; break; | 281 L1: case 1: b = a + 42; break; |
| 264 case 2: a = 'foo'; continue L1; | 282 case 2: a = 'foo'; continue L1; |
| 265 } | 283 } |
| 266 return b; | 284 return b; |
| 267 } | 285 } |
| 268 | 286 |
| 287 testContinue1() { |
| 288 var a = 42; |
| 289 var b; |
| 290 while (true) { |
| 291 b = a + 54; |
| 292 if (b == 42) continue; |
| 293 a = 'foo'; |
| 294 } |
| 295 return b; |
| 296 } |
| 297 |
| 298 testBreak1() { |
| 299 var a = 42; |
| 300 var b; |
| 301 while (true) { |
| 302 b = a + 54; |
| 303 if (b == 42) break; |
| 304 b = 'foo'; |
| 305 } |
| 306 return b; |
| 307 } |
| 308 |
| 309 testContinue2() { |
| 310 var a = 42; |
| 311 var b; |
| 312 while (true) { |
| 313 b = a + 54; |
| 314 if (b == 42) { |
| 315 b = 'foo'; |
| 316 continue; |
| 317 } |
| 318 } |
| 319 return b; |
| 320 } |
| 321 |
| 322 testBreak2() { |
| 323 var a = 42; |
| 324 var b; |
| 325 while (true) { |
| 326 b = a + 54; |
| 327 if (b == 42) { |
| 328 a = 'foo'; |
| 329 break; |
| 330 } |
| 331 } |
| 332 return b; |
| 333 } |
| 334 |
| 269 get topLevelGetter => 42; | 335 get topLevelGetter => 42; |
| 270 returnDynamic() => topLevelGetter(42); | 336 returnDynamic() => topLevelGetter(42); |
| 271 | 337 |
| 272 class A { | 338 class A { |
| 273 factory A() = A.generative; | 339 factory A() = A.generative; |
| 274 A.generative(); | 340 A.generative(); |
| 275 operator==(other) => 42; | 341 operator==(other) => 42; |
| 276 | 342 |
| 277 get myField => 42; | 343 get myField => 42; |
| 278 set myField(a) {} | 344 set myField(a) {} |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 testIsCheck13(topLevelGetter()); | 396 testIsCheck13(topLevelGetter()); |
| 331 testIsCheck14(topLevelGetter()); | 397 testIsCheck14(topLevelGetter()); |
| 332 testIsCheck15(topLevelGetter()); | 398 testIsCheck15(topLevelGetter()); |
| 333 testIsCheck16(topLevelGetter()); | 399 testIsCheck16(topLevelGetter()); |
| 334 testIsCheck17(topLevelGetter()); | 400 testIsCheck17(topLevelGetter()); |
| 335 testIsCheck18(topLevelGetter()); | 401 testIsCheck18(topLevelGetter()); |
| 336 testIsCheck19(topLevelGetter()); | 402 testIsCheck19(topLevelGetter()); |
| 337 returnAsString(); | 403 returnAsString(); |
| 338 returnIntAsNum(); | 404 returnIntAsNum(); |
| 339 returnAsTypedef(); | 405 returnAsTypedef(); |
| 406 testDeadCode(); |
| 407 testLabeledIf(); |
| 340 testSwitch1(); | 408 testSwitch1(); |
| 341 testSwitch2(); | 409 testSwitch2(); |
| 342 testSwitch3(); | 410 testSwitch3(); |
| 411 testContinue1(); |
| 412 testBreak1(); |
| 413 testContinue2(); |
| 414 testBreak2(); |
| 343 new A() == null; | 415 new A() == null; |
| 344 new A()..returnInt1() | 416 new A()..returnInt1() |
| 345 ..returnInt2() | 417 ..returnInt2() |
| 346 ..returnInt3() | 418 ..returnInt3() |
| 347 ..returnInt4() | 419 ..returnInt4() |
| 348 ..returnInt5() | 420 ..returnInt5() |
| 349 ..returnInt6(); | 421 ..returnInt6(); |
| 350 | 422 |
| 351 new B()..returnInt1() | 423 new B()..returnInt1() |
| 352 ..returnInt2() | 424 ..returnInt2() |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 checkReturn('testIsCheck14', typesInferrer.dynamicType); | 477 checkReturn('testIsCheck14', typesInferrer.dynamicType); |
| 406 checkReturn('testIsCheck15', intType); | 478 checkReturn('testIsCheck15', intType); |
| 407 checkReturn('testIsCheck16', typesInferrer.dynamicType); | 479 checkReturn('testIsCheck16', typesInferrer.dynamicType); |
| 408 checkReturn('testIsCheck17', intType); | 480 checkReturn('testIsCheck17', intType); |
| 409 checkReturn('testIsCheck18', typesInferrer.dynamicType); | 481 checkReturn('testIsCheck18', typesInferrer.dynamicType); |
| 410 checkReturn('testIsCheck19', typesInferrer.dynamicType); | 482 checkReturn('testIsCheck19', typesInferrer.dynamicType); |
| 411 checkReturn('returnAsString', | 483 checkReturn('returnAsString', |
| 412 new TypeMask.subtype(compiler.stringClass.computeType(compiler))); | 484 new TypeMask.subtype(compiler.stringClass.computeType(compiler))); |
| 413 checkReturn('returnIntAsNum', typesInferrer.intType); | 485 checkReturn('returnIntAsNum', typesInferrer.intType); |
| 414 checkReturn('returnAsTypedef', typesInferrer.functionType.nullable()); | 486 checkReturn('returnAsTypedef', typesInferrer.functionType.nullable()); |
| 487 checkReturn('testDeadCode', typesInferrer.intType); |
| 488 checkReturn('testLabeledIf', typesInferrer.intType.nullable()); |
| 415 checkReturn('testSwitch1', | 489 checkReturn('testSwitch1', |
| 416 typesInferrer.intType.union(typesInferrer.doubleType, compiler).nullable()); | 490 typesInferrer.intType.union(typesInferrer.doubleType, compiler).nullable()); |
| 417 checkReturn('testSwitch2', typesInferrer.intType); | 491 checkReturn('testSwitch2', typesInferrer.intType); |
| 418 checkReturn('testSwitch3', interceptorType.nullable()); | 492 checkReturn('testSwitch3', interceptorType.nullable()); |
| 493 checkReturn('testContinue1', interceptorType.nullable()); |
| 494 checkReturn('testBreak1', interceptorType.nullable()); |
| 495 checkReturn('testContinue2', interceptorType.nullable()); |
| 496 checkReturn('testBreak2', typesInferrer.intType.nullable()); |
| 419 | 497 |
| 420 checkReturnInClass(String className, String methodName, type) { | 498 checkReturnInClass(String className, String methodName, type) { |
| 421 var cls = findElement(compiler, className); | 499 var cls = findElement(compiler, className); |
| 422 var element = cls.lookupLocalMember(buildSourceString(methodName)); | 500 var element = cls.lookupLocalMember(buildSourceString(methodName)); |
| 423 Expect.equals(type, typesInferrer.internal.returnTypeOf[element]); | 501 Expect.equals(type, typesInferrer.internal.returnTypeOf[element]); |
| 424 } | 502 } |
| 425 | 503 |
| 426 checkReturnInClass('A', 'returnInt1', typesInferrer.intType); | 504 checkReturnInClass('A', 'returnInt1', typesInferrer.intType); |
| 427 checkReturnInClass('A', 'returnInt2', typesInferrer.intType); | 505 checkReturnInClass('A', 'returnInt2', typesInferrer.intType); |
| 428 checkReturnInClass('A', 'returnInt3', typesInferrer.intType); | 506 checkReturnInClass('A', 'returnInt3', typesInferrer.intType); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 441 checkReturnInClass('B', 'returnInt8', typesInferrer.intType); | 519 checkReturnInClass('B', 'returnInt8', typesInferrer.intType); |
| 442 | 520 |
| 443 checkFactoryConstructor(String className) { | 521 checkFactoryConstructor(String className) { |
| 444 var cls = findElement(compiler, className); | 522 var cls = findElement(compiler, className); |
| 445 var element = cls.localLookup(buildSourceString(className)); | 523 var element = cls.localLookup(buildSourceString(className)); |
| 446 Expect.equals(new TypeMask.nonNullExact(cls.rawType), | 524 Expect.equals(new TypeMask.nonNullExact(cls.rawType), |
| 447 typesInferrer.internal.returnTypeOf[element]); | 525 typesInferrer.internal.returnTypeOf[element]); |
| 448 } | 526 } |
| 449 checkFactoryConstructor('A'); | 527 checkFactoryConstructor('A'); |
| 450 } | 528 } |
| OLD | NEW |