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

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

Issue 17017003: Introduce an ElementTypeMask to recognize simple constraints like "the type of parameter foo is the… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 | « tests/compiler/dart2js/concrete_type_inference_test.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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 } 352 }
353 353
354 testReturnElementOfConstList1() { 354 testReturnElementOfConstList1() {
355 return const [42][0]; 355 return const [42][0];
356 } 356 }
357 357
358 testReturnElementOfConstList2() { 358 testReturnElementOfConstList2() {
359 return topLevelConstList[0]; 359 return topLevelConstList[0];
360 } 360 }
361 361
362 testReturnItselfOrInt(a) {
363 if (a) return 42;
364 return testReturnItselfOrInt(a);
365 }
366
362 var topLevelConstList = const [42]; 367 var topLevelConstList = const [42];
363 368
364 get topLevelGetter => 42; 369 get topLevelGetter => 42;
365 returnDynamic() => topLevelGetter(42); 370 returnDynamic() => topLevelGetter(42);
366 returnTopLevelGetter() => topLevelGetter; 371 returnTopLevelGetter() => topLevelGetter;
367 372
368 class A { 373 class A {
369 factory A() = A.generative; 374 factory A() = A.generative;
370 A.generative(); 375 A.generative();
371 operator==(other) => 42; 376 operator==(other) => 42;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 ..returnInt2() 465 ..returnInt2()
461 ..returnInt3() 466 ..returnInt3()
462 ..returnInt4() 467 ..returnInt4()
463 ..returnInt5() 468 ..returnInt5()
464 ..returnInt6() 469 ..returnInt6()
465 ..returnInt7() 470 ..returnInt7()
466 ..returnInt8() 471 ..returnInt8()
467 ..returnInt9(); 472 ..returnInt9();
468 testReturnElementOfConstList1(); 473 testReturnElementOfConstList1();
469 testReturnElementOfConstList2(); 474 testReturnElementOfConstList2();
475 testReturnItselfOrInt(topLevelGetter());
470 } 476 }
471 """; 477 """;
472 478
473 void main() { 479 void main() {
474 Uri uri = new Uri(scheme: 'source'); 480 Uri uri = new Uri(scheme: 'source');
475 var compiler = compilerFor(TEST, uri); 481 var compiler = compilerFor(TEST, uri);
476 compiler.runCompiler(uri); 482 compiler.runCompiler(uri);
477 var typesInferrer = compiler.typesTask.typesInferrer; 483 var typesInferrer = compiler.typesTask.typesInferrer;
478 484
479 checkReturn(String name, type) { 485 checkReturn(String name, type) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 .union(typesInferrer.doubleType, compiler).nullable().simplify(compiler)); 540 .union(typesInferrer.doubleType, compiler).nullable().simplify(compiler));
535 checkReturn('testSwitch2', typesInferrer.intType); 541 checkReturn('testSwitch2', typesInferrer.intType);
536 checkReturn('testSwitch3', interceptorType.nullable()); 542 checkReturn('testSwitch3', interceptorType.nullable());
537 checkReturn('testSwitch4', typesInferrer.intType); 543 checkReturn('testSwitch4', typesInferrer.intType);
538 checkReturn('testContinue1', interceptorType.nullable()); 544 checkReturn('testContinue1', interceptorType.nullable());
539 checkReturn('testBreak1', interceptorType.nullable()); 545 checkReturn('testBreak1', interceptorType.nullable());
540 checkReturn('testContinue2', interceptorType.nullable()); 546 checkReturn('testContinue2', interceptorType.nullable());
541 checkReturn('testBreak2', typesInferrer.intType.nullable()); 547 checkReturn('testBreak2', typesInferrer.intType.nullable());
542 checkReturn('testReturnElementOfConstList1', typesInferrer.intType); 548 checkReturn('testReturnElementOfConstList1', typesInferrer.intType);
543 checkReturn('testReturnElementOfConstList2', typesInferrer.intType); 549 checkReturn('testReturnElementOfConstList2', typesInferrer.intType);
550 checkReturn('testReturnItselfOrInt', typesInferrer.intType);
544 551
545 checkReturnInClass(String className, String methodName, type) { 552 checkReturnInClass(String className, String methodName, type) {
546 var cls = findElement(compiler, className); 553 var cls = findElement(compiler, className);
547 var element = cls.lookupLocalMember(buildSourceString(methodName)); 554 var element = cls.lookupLocalMember(buildSourceString(methodName));
548 Expect.equals(type, 555 Expect.equals(type,
549 typesInferrer.internal.returnTypeOf[element].simplify(compiler)); 556 typesInferrer.internal.returnTypeOf[element].simplify(compiler));
550 } 557 }
551 558
552 checkReturnInClass('A', 'returnInt1', typesInferrer.intType); 559 checkReturnInClass('A', 'returnInt1', typesInferrer.intType);
553 checkReturnInClass('A', 'returnInt2', typesInferrer.intType); 560 checkReturnInClass('A', 'returnInt2', typesInferrer.intType);
(...skipping 14 matching lines...) Expand all
568 checkReturnInClass('B', 'returnInt9', typesInferrer.intType); 575 checkReturnInClass('B', 'returnInt9', typesInferrer.intType);
569 576
570 checkFactoryConstructor(String className) { 577 checkFactoryConstructor(String className) {
571 var cls = findElement(compiler, className); 578 var cls = findElement(compiler, className);
572 var element = cls.localLookup(buildSourceString(className)); 579 var element = cls.localLookup(buildSourceString(className));
573 Expect.equals(new TypeMask.nonNullExact(cls.rawType), 580 Expect.equals(new TypeMask.nonNullExact(cls.rawType),
574 typesInferrer.internal.returnTypeOf[element]); 581 typesInferrer.internal.returnTypeOf[element]);
575 } 582 }
576 checkFactoryConstructor('A'); 583 checkFactoryConstructor('A');
577 } 584 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/concrete_type_inference_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698