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

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

Issue 11194025: Second round of cleanups for new optional parameter semantics. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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
OLDNEW
1 // Copyright (c) 2012, 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 4
5 #import('dart:uri'); 5 #import('dart:uri');
6 6
7 #import("../../../lib/compiler/implementation/leg.dart"); 7 #import("../../../lib/compiler/implementation/leg.dart");
8 #import("../../../lib/compiler/implementation/elements/elements.dart"); 8 #import("../../../lib/compiler/implementation/elements/elements.dart");
9 #import("../../../lib/compiler/implementation/tree/tree.dart"); 9 #import("../../../lib/compiler/implementation/tree/tree.dart");
10 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart"); 10 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart");
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 548
549 VariableDefinitions bNode = bElement.variables.parseNode(compiler); 549 VariableDefinitions bNode = bElement.variables.parseNode(compiler);
550 VariableDefinitions cNode = cElement.variables.parseNode(compiler); 550 VariableDefinitions cNode = cElement.variables.parseNode(compiler);
551 Expect.equals(bNode, cNode); 551 Expect.equals(bNode, cNode);
552 Expect.isNull(bNode.type); 552 Expect.isNull(bNode.type);
553 Expect.isTrue(bNode.modifiers.isVar()); 553 Expect.isTrue(bNode.modifiers.isVar());
554 } 554 }
555 555
556 resolveConstructor(String script, String statement, String className, 556 resolveConstructor(String script, String statement, String className,
557 String constructor, int expectedElementCount, 557 String constructor, int expectedElementCount,
558 [List expectedWarnings = const [], 558 {List expectedWarnings: const [],
559 List expectedErrors = const [], 559 List expectedErrors: const [],
560 String corelib = DEFAULT_CORELIB]) { 560 String corelib: DEFAULT_CORELIB}) {
561 MockCompiler compiler = new MockCompiler(corelib); 561 MockCompiler compiler = new MockCompiler(coreSource: corelib);
562 compiler.parseScript(script); 562 compiler.parseScript(script);
563 compiler.resolveStatement(statement); 563 compiler.resolveStatement(statement);
564 ClassElement classElement = 564 ClassElement classElement =
565 compiler.mainApp.find(buildSourceString(className)); 565 compiler.mainApp.find(buildSourceString(className));
566 Element element = 566 Element element =
567 classElement.lookupConstructor( 567 classElement.lookupConstructor(
568 new Selector.callConstructor(buildSourceString(constructor), 568 new Selector.callConstructor(buildSourceString(constructor),
569 classElement.getLibrary())); 569 classElement.getLibrary()));
570 FunctionExpression tree = element.parseNode(compiler); 570 FunctionExpression tree = element.parseNode(compiler);
571 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 571 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 int foo; int bar; 623 int foo; int bar;
624 A() : this.foo = 1, bar = 2; 624 A() : this.foo = 1, bar = 2;
625 }"""; 625 }""";
626 resolveConstructor(script, "A a = new A();", "A", "A", 2); 626 resolveConstructor(script, "A a = new A();", "A", "A", 2);
627 627
628 script = """class A { 628 script = """class A {
629 int foo; A a; 629 int foo; A a;
630 A() : a.foo = 1; 630 A() : a.foo = 1;
631 }"""; 631 }""";
632 resolveConstructor(script, "A a = new A();", "A", "A", 0, 632 resolveConstructor(script, "A a = new A();", "A", "A", 0,
633 [], [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]); 633 expectedWarnings: [],
634 expectedErrors:
635 [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]);
634 636
635 script = """class A { 637 script = """class A {
636 int foo; 638 int foo;
637 A() : this.foo = 1, this.foo = 2; 639 A() : this.foo = 1, this.foo = 2;
638 }"""; 640 }""";
639 resolveConstructor(script, "A a = new A();", "A", "A", 2, 641 resolveConstructor(script, "A a = new A();", "A", "A", 2,
640 [MessageKind.ALREADY_INITIALIZED], 642 expectedWarnings: [MessageKind.ALREADY_INITIALIZED],
641 [MessageKind.DUPLICATE_INITIALIZER]); 643 expectedErrors: [MessageKind.DUPLICATE_INITIALIZER]);
642 644
643 script = """class A { 645 script = """class A {
644 A() : this.foo = 1; 646 A() : this.foo = 1;
645 }"""; 647 }""";
646 resolveConstructor(script, "A a = new A();", "A", "A", 0, 648 resolveConstructor(script, "A a = new A();", "A", "A", 0,
647 [], [MessageKind.CANNOT_RESOLVE]); 649 expectedWarnings: [],
650 expectedErrors: [MessageKind.CANNOT_RESOLVE]);
648 651
649 script = """class A { 652 script = """class A {
650 int foo; 653 int foo;
651 int bar; 654 int bar;
652 A() : this.foo = bar; 655 A() : this.foo = bar;
653 }"""; 656 }""";
654 resolveConstructor(script, "A a = new A();", "A", "A", 3, 657 resolveConstructor(script, "A a = new A();", "A", "A", 3,
655 [], [MessageKind.NO_INSTANCE_AVAILABLE]); 658 expectedWarnings: [],
659 expectedErrors: [MessageKind.NO_INSTANCE_AVAILABLE]);
656 660
657 script = """class A { 661 script = """class A {
658 int foo() => 42; 662 int foo() => 42;
659 A() : foo(); 663 A() : foo();
660 }"""; 664 }""";
661 resolveConstructor(script, "A a = new A();", "A", "A", 0, 665 resolveConstructor(script, "A a = new A();", "A", "A", 0,
662 [], [MessageKind.CONSTRUCTOR_CALL_EXPECTED]); 666 expectedWarnings: [],
667 expectedErrors: [MessageKind.CONSTRUCTOR_CALL_EXPECTED]);
663 668
664 script = """class A { 669 script = """class A {
665 int i; 670 int i;
666 A.a() : this.b(0); 671 A.a() : this.b(0);
667 A.b(int i); 672 A.b(int i);
668 }"""; 673 }""";
669 resolveConstructor(script, "A a = new A.a();", "A", "a", 1, 674 resolveConstructor(script, "A a = new A.a();", "A", "a", 1);
670 [], []);
671 675
672 script = """class A { 676 script = """class A {
673 int i; 677 int i;
674 A.a() : i = 42, this(0); 678 A.a() : i = 42, this(0);
675 A(int i); 679 A(int i);
676 }"""; 680 }""";
677 resolveConstructor(script, "A a = new A.a();", "A", "a", 2, 681 resolveConstructor(script, "A a = new A.a();", "A", "a", 2,
678 [], [MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER]); 682 expectedWarnings: [],
683 expectedErrors:
684 [MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER]);
679 685
680 script = """class A { 686 script = """class A {
681 int i; 687 int i;
682 A(i); 688 A(i);
683 } 689 }
684 class B extends A { 690 class B extends A {
685 B() : super(0); 691 B() : super(0);
686 }"""; 692 }""";
687 resolveConstructor(script, "B a = new B();", "B", "B", 1, 693 resolveConstructor(script, "B a = new B();", "B", "B", 1);
688 [], []);
689 694
690 script = """class A { 695 script = """class A {
691 int i; 696 int i;
692 A(i); 697 A(i);
693 } 698 }
694 class B extends A { 699 class B extends A {
695 B() : super(0), super(1); 700 B() : super(0), super(1);
696 }"""; 701 }""";
697 resolveConstructor(script, "B b = new B();", "B", "B", 2, 702 resolveConstructor(script, "B b = new B();", "B", "B", 2,
698 [], [MessageKind.DUPLICATE_SUPER_INITIALIZER]); 703 expectedWarnings: [],
704 expectedErrors: [MessageKind.DUPLICATE_SUPER_INITIALIZER]);
699 705
700 script = ""; 706 script = "";
701 final String CORELIB_WITH_INVALID_OBJECT = 707 final String CORELIB_WITH_INVALID_OBJECT =
702 '''print(var obj) {} 708 '''print(var obj) {}
703 class int {} 709 class int {}
704 class double {} 710 class double {}
705 class bool {} 711 class bool {}
706 class String {} 712 class String {}
707 class num {} 713 class num {}
708 class Function {} 714 class Function {}
709 class List {} 715 class List {}
710 class Closure {} 716 class Closure {}
711 class Null {} 717 class Null {}
712 class Dynamic_ {} 718 class Dynamic_ {}
713 class Object { Object() : super(); }'''; 719 class Object { Object() : super(); }''';
714 resolveConstructor(script, "Object o = new Object();", "Object", "Object", 1, 720 resolveConstructor(script, "Object o = new Object();", "Object", "Object", 1,
715 [], [MessageKind.SUPER_INITIALIZER_IN_OBJECT], 721 expectedWarnings: [],
722 expectedErrors: [MessageKind.SUPER_INITIALIZER_IN_OBJECT],
716 corelib: CORELIB_WITH_INVALID_OBJECT); 723 corelib: CORELIB_WITH_INVALID_OBJECT);
717 } 724 }
718 725
719 map(ResolverVisitor visitor) { 726 map(ResolverVisitor visitor) {
720 TreeElementMapping elements = visitor.mapping; 727 TreeElementMapping elements = visitor.mapping;
721 return elements.map; 728 return elements.map;
722 } 729 }
723 730
724 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); 731 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1);
725 732
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 var d = new D(); 792 var d = new D();
786 --d; 793 --d;
787 }"""; 794 }""";
788 final compiler = compileScript(script); 795 final compiler = compileScript(script);
789 796
790 checkMemberResolved(compiler, 'A', operatorName('+', false)); 797 checkMemberResolved(compiler, 'A', operatorName('+', false));
791 checkMemberResolved(compiler, 'B', operatorName('+', false)); 798 checkMemberResolved(compiler, 'B', operatorName('+', false));
792 checkMemberResolved(compiler, 'C', operatorName('-', false)); 799 checkMemberResolved(compiler, 'C', operatorName('-', false));
793 checkMemberResolved(compiler, 'D', operatorName('-', false)); 800 checkMemberResolved(compiler, 'D', operatorName('-', false));
794 } 801 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698