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

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

Issue 11140018: Ensure that ClassElement.lookupConstructor fails when looking up default constructor using Selector… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased. Created 8 years, 1 month 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/dart2jslib.dart" 7 import "../../../lib/compiler/implementation/dart2jslib.dart"
8 hide TreeElementMapping, TreeElements; 8 hide TreeElementMapping, TreeElements;
9 import "../../../lib/compiler/implementation/resolution/resolution.dart"; 9 import "../../../lib/compiler/implementation/resolution/resolution.dart";
10 import "../../../lib/compiler/implementation/elements/elements.dart"; 10 import "../../../lib/compiler/implementation/elements/elements.dart";
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(coreSource: 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 if (constructor !== '') {
568 new Selector.callConstructor(buildSourceString(constructor), 568 element = classElement.lookupConstructor(
569 classElement.getLibrary())); 569 new Selector.callConstructor(buildSourceString(constructor),
570 classElement.getLibrary()));
571 } else {
572 element = classElement.lookupConstructor(
573 new Selector.callDefaultConstructor(classElement.getLibrary()));
574 }
575
570 FunctionExpression tree = element.parseNode(compiler); 576 FunctionExpression tree = element.parseNode(compiler);
571 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 577 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
572 new InitializerResolver(visitor).resolveInitializers(element, tree); 578 new InitializerResolver(visitor).resolveInitializers(element, tree);
573 visitor.visit(tree.body); 579 visitor.visit(tree.body);
574 Expect.equals(expectedElementCount, map(visitor).length); 580 Expect.equals(expectedElementCount, map(visitor).length);
575 581
576 compareWarningKinds(script, expectedWarnings, compiler.warnings); 582 compareWarningKinds(script, expectedWarnings, compiler.warnings);
577 compareWarningKinds(script, expectedErrors, compiler.errors); 583 compareWarningKinds(script, expectedErrors, compiler.errors);
578 } 584 }
579 585
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 Expect.equals(<String>['B', 'C', 'Object'].toString(), 622 Expect.equals(<String>['B', 'C', 'Object'].toString(),
617 asSortedStrings(supertypes).toString()); 623 asSortedStrings(supertypes).toString());
618 } 624 }
619 625
620 testInitializers() { 626 testInitializers() {
621 String script; 627 String script;
622 script = """class A { 628 script = """class A {
623 int foo; int bar; 629 int foo; int bar;
624 A() : this.foo = 1, bar = 2; 630 A() : this.foo = 1, bar = 2;
625 }"""; 631 }""";
626 resolveConstructor(script, "A a = new A();", "A", "A", 2); 632 resolveConstructor(script, "A a = new A();", "A", "", 2);
627 633
628 script = """class A { 634 script = """class A {
629 int foo; A a; 635 int foo; A a;
630 A() : a.foo = 1; 636 A() : a.foo = 1;
631 }"""; 637 }""";
632 resolveConstructor(script, "A a = new A();", "A", "A", 0, 638 resolveConstructor(script, "A a = new A();", "A", "", 0,
633 expectedWarnings: [], 639 expectedWarnings: [],
634 expectedErrors: 640 expectedErrors:
635 [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]); 641 [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]);
636 642
637 script = """class A { 643 script = """class A {
638 int foo; 644 int foo;
639 A() : this.foo = 1, this.foo = 2; 645 A() : this.foo = 1, this.foo = 2;
640 }"""; 646 }""";
641 resolveConstructor(script, "A a = new A();", "A", "A", 2, 647 resolveConstructor(script, "A a = new A();", "A", "", 2,
642 expectedWarnings: [MessageKind.ALREADY_INITIALIZED], 648 expectedWarnings: [MessageKind.ALREADY_INITIALIZED],
643 expectedErrors: [MessageKind.DUPLICATE_INITIALIZER]); 649 expectedErrors: [MessageKind.DUPLICATE_INITIALIZER]);
644 650
645 script = """class A { 651 script = """class A {
646 A() : this.foo = 1; 652 A() : this.foo = 1;
647 }"""; 653 }""";
648 resolveConstructor(script, "A a = new A();", "A", "A", 0, 654 resolveConstructor(script, "A a = new A();", "A", "", 0,
649 expectedWarnings: [], 655 expectedWarnings: [],
650 expectedErrors: [MessageKind.CANNOT_RESOLVE]); 656 expectedErrors: [MessageKind.CANNOT_RESOLVE]);
651 657
652 script = """class A { 658 script = """class A {
653 int foo; 659 int foo;
654 int bar; 660 int bar;
655 A() : this.foo = bar; 661 A() : this.foo = bar;
656 }"""; 662 }""";
657 resolveConstructor(script, "A a = new A();", "A", "A", 3, 663 resolveConstructor(script, "A a = new A();", "A", "", 3,
658 expectedWarnings: [], 664 expectedWarnings: [],
659 expectedErrors: [MessageKind.NO_INSTANCE_AVAILABLE]); 665 expectedErrors: [MessageKind.NO_INSTANCE_AVAILABLE]);
660 666
661 script = """class A { 667 script = """class A {
662 int foo() => 42; 668 int foo() => 42;
663 A() : foo(); 669 A() : foo();
664 }"""; 670 }""";
665 resolveConstructor(script, "A a = new A();", "A", "A", 0, 671 resolveConstructor(script, "A a = new A();", "A", "", 0,
666 expectedWarnings: [], 672 expectedWarnings: [],
667 expectedErrors: [MessageKind.CONSTRUCTOR_CALL_EXPECTED]); 673 expectedErrors: [MessageKind.CONSTRUCTOR_CALL_EXPECTED]);
668 674
669 script = """class A { 675 script = """class A {
670 int i; 676 int i;
671 A.a() : this.b(0); 677 A.a() : this.b(0);
672 A.b(int i); 678 A.b(int i);
673 }"""; 679 }""";
674 resolveConstructor(script, "A a = new A.a();", "A", "a", 1); 680 resolveConstructor(script, "A a = new A.a();", "A", "a", 1);
675 681
676 script = """class A { 682 script = """class A {
677 int i; 683 int i;
678 A.a() : i = 42, this(0); 684 A.a() : i = 42, this(0);
679 A(int i); 685 A(int i);
680 }"""; 686 }""";
681 resolveConstructor(script, "A a = new A.a();", "A", "a", 2, 687 resolveConstructor(script, "A a = new A.a();", "A", "a", 2,
682 expectedWarnings: [], 688 expectedWarnings: [],
683 expectedErrors: 689 expectedErrors:
684 [MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER]); 690 [MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER]);
685 691
686 script = """class A { 692 script = """class A {
687 int i; 693 int i;
688 A(i); 694 A(i);
689 } 695 }
690 class B extends A { 696 class B extends A {
691 B() : super(0); 697 B() : super(0);
692 }"""; 698 }""";
693 resolveConstructor(script, "B a = new B();", "B", "B", 1); 699 resolveConstructor(script, "B a = new B();", "B", "", 1);
694 700
695 script = """class A { 701 script = """class A {
696 int i; 702 int i;
697 A(i); 703 A(i);
698 } 704 }
699 class B extends A { 705 class B extends A {
700 B() : super(0), super(1); 706 B() : super(0), super(1);
701 }"""; 707 }""";
702 resolveConstructor(script, "B b = new B();", "B", "B", 2, 708 resolveConstructor(script, "B b = new B();", "B", "", 2,
703 expectedWarnings: [], 709 expectedWarnings: [],
704 expectedErrors: [MessageKind.DUPLICATE_SUPER_INITIALIZER]); 710 expectedErrors: [MessageKind.DUPLICATE_SUPER_INITIALIZER]);
705 711
706 script = ""; 712 script = "";
707 final String CORELIB_WITH_INVALID_OBJECT = 713 final String CORELIB_WITH_INVALID_OBJECT =
708 '''print(var obj) {} 714 '''print(var obj) {}
709 class int {} 715 class int {}
710 class double {} 716 class double {}
711 class bool {} 717 class bool {}
712 class String {} 718 class String {}
713 class num {} 719 class num {}
714 class Function {} 720 class Function {}
715 class List {} 721 class List {}
716 class Map {} 722 class Map {}
717 class Closure {} 723 class Closure {}
718 class Null {} 724 class Null {}
719 class Dynamic_ {} 725 class Dynamic_ {}
720 class Object { Object() : super(); }'''; 726 class Object { Object() : super(); }''';
721 resolveConstructor(script, "Object o = new Object();", "Object", "Object", 1, 727 resolveConstructor(script, "Object o = new Object();", "Object", "", 1,
722 expectedWarnings: [], 728 expectedWarnings: [],
723 expectedErrors: [MessageKind.SUPER_INITIALIZER_IN_OBJECT], 729 expectedErrors: [MessageKind.SUPER_INITIALIZER_IN_OBJECT],
724 corelib: CORELIB_WITH_INVALID_OBJECT); 730 corelib: CORELIB_WITH_INVALID_OBJECT);
725 } 731 }
726 732
727 map(ResolverVisitor visitor) { 733 map(ResolverVisitor visitor) {
728 TreeElementMapping elements = visitor.mapping; 734 TreeElementMapping elements = visitor.mapping;
729 return elements.map; 735 return elements.map;
730 } 736 }
731 737
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 var d = new D(); 799 var d = new D();
794 --d; 800 --d;
795 }"""; 801 }""";
796 final compiler = compileScript(script); 802 final compiler = compileScript(script);
797 803
798 checkMemberResolved(compiler, 'A', operatorName('+', false)); 804 checkMemberResolved(compiler, 'A', operatorName('+', false));
799 checkMemberResolved(compiler, 'B', operatorName('+', false)); 805 checkMemberResolved(compiler, 'B', operatorName('+', false));
800 checkMemberResolved(compiler, 'C', operatorName('-', false)); 806 checkMemberResolved(compiler, 'C', operatorName('-', false));
801 checkMemberResolved(compiler, 'D', operatorName('-', false)); 807 checkMemberResolved(compiler, 'D', operatorName('-', false));
802 } 808 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698