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

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: Use [==] and [!=] instead of [identical] for SourceString comparison. 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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 resolveConstructor(String script, String statement, String className, 561 resolveConstructor(String script, String statement, String className,
562 String constructor, int expectedElementCount, 562 String constructor, int expectedElementCount,
563 {List expectedWarnings: const [], 563 {List expectedWarnings: const [],
564 List expectedErrors: const [], 564 List expectedErrors: const [],
565 String corelib: DEFAULT_CORELIB}) { 565 String corelib: DEFAULT_CORELIB}) {
566 MockCompiler compiler = new MockCompiler(coreSource: corelib); 566 MockCompiler compiler = new MockCompiler(coreSource: corelib);
567 compiler.parseScript(script); 567 compiler.parseScript(script);
568 compiler.resolveStatement(statement); 568 compiler.resolveStatement(statement);
569 ClassElement classElement = 569 ClassElement classElement =
570 compiler.mainApp.find(buildSourceString(className)); 570 compiler.mainApp.find(buildSourceString(className));
571 Element element = 571 Element element;
572 classElement.lookupConstructor( 572 if (constructor !== '') {
ahe 2012/10/26 11:08:53 !=
573 new Selector.callConstructor(buildSourceString(constructor), 573 element = classElement.lookupConstructor(
574 classElement.getLibrary())); 574 new Selector.callConstructor(buildSourceString(constructor),
575 classElement.getLibrary()));
576 } else {
577 element = classElement.lookupConstructor(
578 new Selector.callDefaultConstructor(classElement.getLibrary()));
579 }
580
575 FunctionExpression tree = element.parseNode(compiler); 581 FunctionExpression tree = element.parseNode(compiler);
576 ResolverVisitor visitor = 582 ResolverVisitor visitor =
577 new ResolverVisitor(compiler, element, 583 new ResolverVisitor(compiler, element,
578 new CollectingTreeElements(element)); 584 new CollectingTreeElements(element));
579 new InitializerResolver(visitor).resolveInitializers(element, tree); 585 new InitializerResolver(visitor).resolveInitializers(element, tree);
580 visitor.visit(tree.body); 586 visitor.visit(tree.body);
581 Expect.equals(expectedElementCount, map(visitor).length); 587 Expect.equals(expectedElementCount, map(visitor).length);
582 588
583 compareWarningKinds(script, expectedWarnings, compiler.warnings); 589 compareWarningKinds(script, expectedWarnings, compiler.warnings);
584 compareWarningKinds(script, expectedErrors, compiler.errors); 590 compareWarningKinds(script, expectedErrors, compiler.errors);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 Expect.equals(<String>['B', 'C', 'Object'].toString(), 629 Expect.equals(<String>['B', 'C', 'Object'].toString(),
624 asSortedStrings(supertypes).toString()); 630 asSortedStrings(supertypes).toString());
625 } 631 }
626 632
627 testInitializers() { 633 testInitializers() {
628 String script; 634 String script;
629 script = """class A { 635 script = """class A {
630 int foo; int bar; 636 int foo; int bar;
631 A() : this.foo = 1, bar = 2; 637 A() : this.foo = 1, bar = 2;
632 }"""; 638 }""";
633 resolveConstructor(script, "A a = new A();", "A", "A", 2); 639 resolveConstructor(script, "A a = new A();", "A", "", 2);
634 640
635 script = """class A { 641 script = """class A {
636 int foo; A a; 642 int foo; A a;
637 A() : a.foo = 1; 643 A() : a.foo = 1;
638 }"""; 644 }""";
639 resolveConstructor(script, "A a = new A();", "A", "A", 0, 645 resolveConstructor(script, "A a = new A();", "A", "", 0,
640 expectedWarnings: [], 646 expectedWarnings: [],
641 expectedErrors: 647 expectedErrors:
642 [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]); 648 [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]);
643 649
644 script = """class A { 650 script = """class A {
645 int foo; 651 int foo;
646 A() : this.foo = 1, this.foo = 2; 652 A() : this.foo = 1, this.foo = 2;
647 }"""; 653 }""";
648 resolveConstructor(script, "A a = new A();", "A", "A", 2, 654 resolveConstructor(script, "A a = new A();", "A", "", 2,
649 expectedWarnings: [MessageKind.ALREADY_INITIALIZED], 655 expectedWarnings: [MessageKind.ALREADY_INITIALIZED],
650 expectedErrors: [MessageKind.DUPLICATE_INITIALIZER]); 656 expectedErrors: [MessageKind.DUPLICATE_INITIALIZER]);
651 657
652 script = """class A { 658 script = """class A {
653 A() : this.foo = 1; 659 A() : this.foo = 1;
654 }"""; 660 }""";
655 resolveConstructor(script, "A a = new A();", "A", "A", 0, 661 resolveConstructor(script, "A a = new A();", "A", "", 0,
656 expectedWarnings: [], 662 expectedWarnings: [],
657 expectedErrors: [MessageKind.CANNOT_RESOLVE]); 663 expectedErrors: [MessageKind.CANNOT_RESOLVE]);
658 664
659 script = """class A { 665 script = """class A {
660 int foo; 666 int foo;
661 int bar; 667 int bar;
662 A() : this.foo = bar; 668 A() : this.foo = bar;
663 }"""; 669 }""";
664 resolveConstructor(script, "A a = new A();", "A", "A", 3, 670 resolveConstructor(script, "A a = new A();", "A", "", 3,
665 expectedWarnings: [], 671 expectedWarnings: [],
666 expectedErrors: [MessageKind.NO_INSTANCE_AVAILABLE]); 672 expectedErrors: [MessageKind.NO_INSTANCE_AVAILABLE]);
667 673
668 script = """class A { 674 script = """class A {
669 int foo() => 42; 675 int foo() => 42;
670 A() : foo(); 676 A() : foo();
671 }"""; 677 }""";
672 resolveConstructor(script, "A a = new A();", "A", "A", 0, 678 resolveConstructor(script, "A a = new A();", "A", "", 0,
673 expectedWarnings: [], 679 expectedWarnings: [],
674 expectedErrors: [MessageKind.CONSTRUCTOR_CALL_EXPECTED]); 680 expectedErrors: [MessageKind.CONSTRUCTOR_CALL_EXPECTED]);
675 681
676 script = """class A { 682 script = """class A {
677 int i; 683 int i;
678 A.a() : this.b(0); 684 A.a() : this.b(0);
679 A.b(int i); 685 A.b(int i);
680 }"""; 686 }""";
681 resolveConstructor(script, "A a = new A.a();", "A", "a", 1); 687 resolveConstructor(script, "A a = new A.a();", "A", "a", 1);
682 688
683 script = """class A { 689 script = """class A {
684 int i; 690 int i;
685 A.a() : i = 42, this(0); 691 A.a() : i = 42, this(0);
686 A(int i); 692 A(int i);
687 }"""; 693 }""";
688 resolveConstructor(script, "A a = new A.a();", "A", "a", 2, 694 resolveConstructor(script, "A a = new A.a();", "A", "a", 2,
689 expectedWarnings: [], 695 expectedWarnings: [],
690 expectedErrors: 696 expectedErrors:
691 [MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER]); 697 [MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER]);
692 698
693 script = """class A { 699 script = """class A {
694 int i; 700 int i;
695 A(i); 701 A(i);
696 } 702 }
697 class B extends A { 703 class B extends A {
698 B() : super(0); 704 B() : super(0);
699 }"""; 705 }""";
700 resolveConstructor(script, "B a = new B();", "B", "B", 1); 706 resolveConstructor(script, "B a = new B();", "B", "", 1);
701 707
702 script = """class A { 708 script = """class A {
703 int i; 709 int i;
704 A(i); 710 A(i);
705 } 711 }
706 class B extends A { 712 class B extends A {
707 B() : super(0), super(1); 713 B() : super(0), super(1);
708 }"""; 714 }""";
709 resolveConstructor(script, "B b = new B();", "B", "B", 2, 715 resolveConstructor(script, "B b = new B();", "B", "", 2,
710 expectedWarnings: [], 716 expectedWarnings: [],
711 expectedErrors: [MessageKind.DUPLICATE_SUPER_INITIALIZER]); 717 expectedErrors: [MessageKind.DUPLICATE_SUPER_INITIALIZER]);
712 718
713 script = ""; 719 script = "";
714 final String CORELIB_WITH_INVALID_OBJECT = 720 final String CORELIB_WITH_INVALID_OBJECT =
715 '''print(var obj) {} 721 '''print(var obj) {}
716 class int {} 722 class int {}
717 class double {} 723 class double {}
718 class bool {} 724 class bool {}
719 class String {} 725 class String {}
720 class num {} 726 class num {}
721 class Function {} 727 class Function {}
722 class List {} 728 class List {}
723 class Map {} 729 class Map {}
724 class Closure {} 730 class Closure {}
725 class Null {} 731 class Null {}
726 class Dynamic_ {} 732 class Dynamic_ {}
727 class Object { Object() : super(); }'''; 733 class Object { Object() : super(); }''';
728 resolveConstructor(script, "Object o = new Object();", "Object", "Object", 1, 734 resolveConstructor(script, "Object o = new Object();", "Object", "", 1,
729 expectedWarnings: [], 735 expectedWarnings: [],
730 expectedErrors: [MessageKind.SUPER_INITIALIZER_IN_OBJECT], 736 expectedErrors: [MessageKind.SUPER_INITIALIZER_IN_OBJECT],
731 corelib: CORELIB_WITH_INVALID_OBJECT); 737 corelib: CORELIB_WITH_INVALID_OBJECT);
732 } 738 }
733 739
734 map(ResolverVisitor visitor) { 740 map(ResolverVisitor visitor) {
735 TreeElementMapping elements = visitor.mapping; 741 TreeElementMapping elements = visitor.mapping;
736 return elements.map; 742 return elements.map;
737 } 743 }
738 744
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 var d = new D(); 806 var d = new D();
801 --d; 807 --d;
802 }"""; 808 }""";
803 final compiler = compileScript(script); 809 final compiler = compileScript(script);
804 810
805 checkMemberResolved(compiler, 'A', operatorName('+', false)); 811 checkMemberResolved(compiler, 'A', operatorName('+', false));
806 checkMemberResolved(compiler, 'B', operatorName('+', false)); 812 checkMemberResolved(compiler, 'B', operatorName('+', false));
807 checkMemberResolved(compiler, 'C', operatorName('-', false)); 813 checkMemberResolved(compiler, 'C', operatorName('-', false));
808 checkMemberResolved(compiler, 'D', operatorName('-', false)); 814 checkMemberResolved(compiler, 'D', operatorName('-', false));
809 } 815 }
OLDNEW
« no previous file with comments | « tests/co19/co19-dart2js.status ('k') | tests/compiler/dart2js_extra/this_redirecting_constructor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698