Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: tests/compiler/dart2js/simple_inferrer_test.dart

Issue 23050002: Handle switch with default case, and do/while loop better in the inferrer. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/types/inferrer_visitor.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 var a = 42; 289 var a = 42;
290 var b; 290 var b;
291 switch (topLevelGetter) { 291 switch (topLevelGetter) {
292 L1: case 1: b = a + 42; break; 292 L1: case 1: b = a + 42; break;
293 case 2: a = 'foo'; continue L1; 293 case 2: a = 'foo'; continue L1;
294 } 294 }
295 return b; 295 return b;
296 } 296 }
297 297
298 testSwitch4() { 298 testSwitch4() {
299 switch(topLevelGetter) { 299 switch (topLevelGetter) {
300 case 1: break; 300 case 1: break;
301 default: break; 301 default: break;
302 } 302 }
303 return 42; 303 return 42;
304 } 304 }
305 305
306 testSwitch5() {
307 switch (topLevelGetter) {
308 case 1: return 1;
309 default: return 2;
310 }
311 }
312
306 testContinue1() { 313 testContinue1() {
307 var a = 42; 314 var a = 42;
308 var b; 315 var b;
309 while (true) { 316 while (true) {
310 b = a + 54; 317 b = a + 54;
311 if (b == 42) continue; 318 if (b == 42) continue;
312 a = 'foo'; 319 a = 'foo';
313 } 320 }
314 return b; 321 return b;
315 } 322 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 364
358 testReturnElementOfConstList2() { 365 testReturnElementOfConstList2() {
359 return topLevelConstList[0]; 366 return topLevelConstList[0];
360 } 367 }
361 368
362 testReturnItselfOrInt(a) { 369 testReturnItselfOrInt(a) {
363 if (a) return 42; 370 if (a) return 42;
364 return testReturnItselfOrInt(a); 371 return testReturnItselfOrInt(a);
365 } 372 }
366 373
374 testDoWhile1() {
375 var a = 42;
376 do {
377 a = 'foo';
378 } while (true);
379 return a;
380 }
381
382 testDoWhile2() {
383 var a = 42;
384 do {
385 a = 'foo';
386 return;
387 } while (true);
388 return a;
389 }
390
391 testDoWhile3() {
392 var a = 42;
393 do {
394 a = 'foo';
395 if (true) continue;
396 return 42;
397 } while (true);
398 return a;
399 }
400
401 testDoWhile4() {
402 var a = 'foo';
403 do {
404 a = 54;
405 if (true) break;
406 return 3.5;
407 } while (true);
408 return a;
409 }
410
367 testReturnInvokeDynamicGetter() => new A().myFactory(); 411 testReturnInvokeDynamicGetter() => new A().myFactory();
368 412
369 var topLevelConstList = const [42]; 413 var topLevelConstList = const [42];
370 414
371 get topLevelGetter => 42; 415 get topLevelGetter => 42;
372 returnDynamic() => topLevelGetter(42); 416 returnDynamic() => topLevelGetter(42);
373 returnTopLevelGetter() => topLevelGetter; 417 returnTopLevelGetter() => topLevelGetter;
374 418
375 class A { 419 class A {
376 factory A() = A.generative; 420 factory A() = A.generative;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 returnAsString(); 490 returnAsString();
447 returnIntAsNum(); 491 returnIntAsNum();
448 returnAsTypedef(); 492 returnAsTypedef();
449 returnTopLevelGetter(); 493 returnTopLevelGetter();
450 testDeadCode(); 494 testDeadCode();
451 testLabeledIf(); 495 testLabeledIf();
452 testSwitch1(); 496 testSwitch1();
453 testSwitch2(); 497 testSwitch2();
454 testSwitch3(); 498 testSwitch3();
455 testSwitch4(); 499 testSwitch4();
500 testSwitch5();
456 testContinue1(); 501 testContinue1();
457 testBreak1(); 502 testBreak1();
458 testContinue2(); 503 testContinue2();
459 testBreak2(); 504 testBreak2();
505 testDoWhile1();
506 testDoWhile2();
507 testDoWhile3();
508 testDoWhile4();
460 new A() == null; 509 new A() == null;
461 new A()..returnInt1() 510 new A()..returnInt1()
462 ..returnInt2() 511 ..returnInt2()
463 ..returnInt3() 512 ..returnInt3()
464 ..returnInt4() 513 ..returnInt4()
465 ..returnInt5() 514 ..returnInt5()
466 ..returnInt6(); 515 ..returnInt6();
467 516
468 new B()..returnInt1() 517 new B()..returnInt1()
469 ..returnInt2() 518 ..returnInt2()
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 checkReturn('testIsCheck20', typesTask.dynamicType.nonNullable()); 586 checkReturn('testIsCheck20', typesTask.dynamicType.nonNullable());
538 checkReturn('returnAsString', 587 checkReturn('returnAsString',
539 new TypeMask.subtype(compiler.stringClass.computeType(compiler))); 588 new TypeMask.subtype(compiler.stringClass.computeType(compiler)));
540 checkReturn('returnIntAsNum', typesTask.intType); 589 checkReturn('returnIntAsNum', typesTask.intType);
541 checkReturn('returnAsTypedef', typesTask.functionType.nullable()); 590 checkReturn('returnAsTypedef', typesTask.functionType.nullable());
542 checkReturn('returnTopLevelGetter', typesTask.intType); 591 checkReturn('returnTopLevelGetter', typesTask.intType);
543 checkReturn('testDeadCode', typesTask.intType); 592 checkReturn('testDeadCode', typesTask.intType);
544 checkReturn('testLabeledIf', typesTask.intType.nullable()); 593 checkReturn('testLabeledIf', typesTask.intType.nullable());
545 checkReturn('testSwitch1', typesTask.intType 594 checkReturn('testSwitch1', typesTask.intType
546 .union(typesTask.doubleType, compiler).nullable().simplify(compiler)); 595 .union(typesTask.doubleType, compiler).nullable().simplify(compiler));
547 // TODO(12320): testSwitch2 should be non-nullable. The quick fix for 12320 596 checkReturn('testSwitch2', typesTask.intType);
548 // models control flow through as though there is an additional empty default
549 // case.
550 checkReturn('testSwitch2', typesTask.intType.nullable());
551 checkReturn('testSwitch3', interceptorType.nullable()); 597 checkReturn('testSwitch3', interceptorType.nullable());
552 checkReturn('testSwitch4', typesTask.intType); 598 checkReturn('testSwitch4', typesTask.intType);
599 checkReturn('testSwitch5', typesTask.intType);
553 checkReturn('testContinue1', interceptorType.nullable()); 600 checkReturn('testContinue1', interceptorType.nullable());
554 checkReturn('testBreak1', interceptorType.nullable()); 601 checkReturn('testBreak1', interceptorType.nullable());
555 checkReturn('testContinue2', interceptorType.nullable()); 602 checkReturn('testContinue2', interceptorType.nullable());
556 checkReturn('testBreak2', typesTask.intType.nullable()); 603 checkReturn('testBreak2', typesTask.intType.nullable());
557 checkReturn('testReturnElementOfConstList1', typesTask.intType); 604 checkReturn('testReturnElementOfConstList1', typesTask.intType);
558 checkReturn('testReturnElementOfConstList2', typesTask.intType); 605 checkReturn('testReturnElementOfConstList2', typesTask.intType);
559 checkReturn('testReturnItselfOrInt', typesTask.intType); 606 checkReturn('testReturnItselfOrInt', typesTask.intType);
560 checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType); 607 checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType);
561 608
609 checkReturn('testDoWhile1', typesTask.stringType);
610 checkReturn('testDoWhile2', typesTask.nullType);
611 checkReturn('testDoWhile3', interceptorType);
612 checkReturn('testDoWhile4', typesTask.numType);
613
562 checkReturnInClass(String className, String methodName, type) { 614 checkReturnInClass(String className, String methodName, type) {
563 var cls = findElement(compiler, className); 615 var cls = findElement(compiler, className);
564 var element = cls.lookupLocalMember(buildSourceString(methodName)); 616 var element = cls.lookupLocalMember(buildSourceString(methodName));
565 Expect.equals(type, 617 Expect.equals(type,
566 typesInferrer.getReturnTypeOfElement(element).simplify(compiler)); 618 typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
567 } 619 }
568 620
569 checkReturnInClass('A', 'returnInt1', typesTask.intType); 621 checkReturnInClass('A', 'returnInt1', typesTask.intType);
570 checkReturnInClass('A', 'returnInt2', typesTask.intType); 622 checkReturnInClass('A', 'returnInt2', typesTask.intType);
571 checkReturnInClass('A', 'returnInt3', typesTask.intType); 623 checkReturnInClass('A', 'returnInt3', typesTask.intType);
(...skipping 13 matching lines...) Expand all
585 checkReturnInClass('B', 'returnInt9', typesTask.intType); 637 checkReturnInClass('B', 'returnInt9', typesTask.intType);
586 638
587 checkFactoryConstructor(String className, String factoryName) { 639 checkFactoryConstructor(String className, String factoryName) {
588 var cls = findElement(compiler, className); 640 var cls = findElement(compiler, className);
589 var element = cls.localLookup(buildSourceString(factoryName)); 641 var element = cls.localLookup(buildSourceString(factoryName));
590 Expect.equals(new TypeMask.nonNullExact(cls.rawType), 642 Expect.equals(new TypeMask.nonNullExact(cls.rawType),
591 typesInferrer.getReturnTypeOfElement(element)); 643 typesInferrer.getReturnTypeOfElement(element));
592 } 644 }
593 checkFactoryConstructor('A', ''); 645 checkFactoryConstructor('A', '');
594 } 646 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/types/inferrer_visitor.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698