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

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

Issue 11348067: Fix operator handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Apply style remarks to the rest the file. Created 8 years 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/concrete_types_inferrer.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) 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 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; 6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t";
7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt'; 7 import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da rt';
8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; 8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart';
9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'; 9 import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart';
10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; 10 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart';
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 */ 135 */
136 void checkFieldHasUknownType(String className, String fieldName) { 136 void checkFieldHasUknownType(String className, String fieldName) {
137 return Expect.isTrue( 137 return Expect.isTrue(
138 inferrer.inferredFieldTypes[findField(className, fieldName)] 138 inferrer.inferredFieldTypes[findField(className, fieldName)]
139 .isUnkown()); 139 .isUnkown());
140 } 140 }
141 } 141 }
142 142
143 const String CORELIB = r''' 143 const String CORELIB = r'''
144 print(var obj) {} 144 print(var obj) {}
145 abstract class num { operator +(x); operator *(x); operator -(x); } 145 abstract class num {
146 operator +(x);
147 operator *(x);
148 operator -(x);
149 operator ==(x);
150 }
146 abstract class int extends num { } 151 abstract class int extends num { }
147 abstract class double extends num { } 152 abstract class double extends num { }
148 class bool {} 153 class bool {}
149 class String {} 154 class String {}
150 class Object {} 155 class Object {}
151 class Function {} 156 class Function {}
152 abstract class List {} 157 abstract class List {}
153 abstract class Map {} 158 abstract class Map {}
154 class Closure {} 159 class Closure {}
155 class Null {} 160 class Null {}
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 var x = new A() < "foo"; 634 var x = new A() < "foo";
630 var y = new A() << "foo"; 635 var y = new A() << "foo";
631 x; y; 636 x; y;
632 } 637 }
633 """; 638 """;
634 AnalysisResult result = analyze(source); 639 AnalysisResult result = analyze(source);
635 result.checkNodeHasType('x', [result.int]); 640 result.checkNodeHasType('x', [result.int]);
636 result.checkNodeHasType('y', [result.string]); 641 result.checkNodeHasType('y', [result.string]);
637 } 642 }
638 643
644 testSetIndexOperator() {
645 final String source = r"""
646 class A {
647 var witness1;
648 var witness2;
649 operator []=(i, x) { witness1 = i; witness2 = x; }
650 }
651 main() {
652 var x = new A()[42] = "abc";
653 x;
654 }
655 """;
656 AnalysisResult result = analyze(source);
657 result.checkNodeHasType('x', [result.string]);
658 // TODO(polux): the two following results should be [:[null, string:], see
659 // testFieldInitialization().
660 result.checkFieldHasType('A', 'witness1', [result.int]);
661 result.checkFieldHasType('A', 'witness2', [result.string]);
662 }
663
639 testCompoundOperators1() { 664 testCompoundOperators1() {
640 final String source = r""" 665 final String source = r"""
641 class A { 666 class A {
642 operator +(x) => "foo"; 667 operator +(x) => "foo";
643 } 668 }
644 main() { 669 main() {
645 var x1 = 1; x1++; 670 var x1 = 1;
646 var x2 = 1; ++x2; 671 x1++;
647 var x3 = new A(); x3++; 672 var x2 = 1;
648 var x4 = new A(); ++x4; 673 ++x2;
674 var x3 = 1;
675 x3 += 42;
676 var x4 = new A();
677 x4++;
678 var x5 = new A();
679 ++x5;
680 var x6 = new A();
681 x6 += true;
649 682
650 x1; x2; x3; x4; 683 x1; x2; x3; x4; x5; x6;
651 } 684 }
652 """; 685 """;
653 AnalysisResult result = analyze(source); 686 AnalysisResult result = analyze(source);
654 result.checkNodeHasType('x1', [result.int]); 687 result.checkNodeHasType('x1', [result.int]);
655 result.checkNodeHasType('x2', [result.int]); 688 result.checkNodeHasType('x2', [result.int]);
656 result.checkNodeHasType('x3', [result.string]); 689 result.checkNodeHasType('x3', [result.int]);
657 result.checkNodeHasType('x4', [result.string]); 690 result.checkNodeHasType('x4', [result.string]);
691 result.checkNodeHasType('x5', [result.string]);
692 result.checkNodeHasType('x6', [result.string]);
658 } 693 }
659 694
660 695
661 testCompoundOperators2() { 696 testCompoundOperators2() {
662 final String source = r""" 697 final String source = r"""
663 class A { 698 class A {
664 var xx; 699 var xx;
700 var yy;
665 var witness1; 701 var witness1;
666 var witness2; 702 var witness2;
703 var witness3;
704 var witness4;
667 705
668 A(this.xx); 706 A(this.xx, this.yy);
669 get x { witness1 = "foo"; return xx; } 707 get x { witness1 = "foo"; return xx; }
670 set x(y) { witness2 = "foo"; xx = y; } 708 set x(a) { witness2 = "foo"; xx = a; }
709 get y { witness3 = "foo"; return yy; }
710 set y(a) { witness4 = "foo"; yy = a; }
671 } 711 }
672 main () { 712 main () {
673 var a = new A(1); 713 var a = new A(1, 1);
674 a.x++; 714 a.x++;
715 a.y++;
675 } 716 }
676 """; 717 """;
677 AnalysisResult result = analyze(source); 718 AnalysisResult result = analyze(source);
678 result.checkFieldHasType('A', 'xx', [result.int]); 719 result.checkFieldHasType('A', 'xx', [result.int]);
679 // TODO(polux): the two following results should be {null, string}, see 720 result.checkFieldHasType('A', 'yy', [result.int]);
680 // fieldInitialization(). 721 // TODO(polux): the four following results should be [:[null, string]:], see
722 // testFieldInitialization().
681 result.checkFieldHasType('A', 'witness1', [result.string]); 723 result.checkFieldHasType('A', 'witness1', [result.string]);
682 result.checkFieldHasType('A', 'witness2', [result.string]); 724 result.checkFieldHasType('A', 'witness2', [result.string]);
725 result.checkFieldHasType('A', 'witness3', [result.string]);
726 result.checkFieldHasType('A', 'witness4', [result.string]);
727 }
728
729 testInequality() {
730 final String source = r"""
731 class A {
732 var witness;
733 operator ==(x) { witness = "foo"; return "abc"; }
734 }
735 class B {
736 operator ==(x) { throw "error"; }
737 }
738 main() {
739 var foo = 1 != 2;
740 var bar = new A() != 2;
741 var baz = new B() != 2;
742 foo; bar; baz;
743 }
744 """;
745 AnalysisResult result = analyze(source);
746 result.checkNodeHasType('foo', [result.bool]);
747 result.checkNodeHasType('bar', [result.bool]);
748 result.checkNodeHasType('baz', []);
749 // TODO(polux): the following result should be [:[null, string]:], see
750 // fieldInitialization().
751 result.checkFieldHasType('A', 'witness', [result.string]);
683 } 752 }
684 753
685 testFieldInitialization() { 754 testFieldInitialization() {
686 final String source = r""" 755 final String source = r"""
687 class A { 756 class A {
688 var x; 757 var x;
689 var y = 1; 758 var y = 1;
690 } 759 }
691 main () { 760 main () {
692 new A(); 761 new A();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 testSetters(); 823 testSetters();
755 testNamedParameters(); 824 testNamedParameters();
756 testListLiterals(); 825 testListLiterals();
757 testMapLiterals(); 826 testMapLiterals();
758 testReturn(); 827 testReturn();
759 // testNoReturn(); // right now we infer the empty type instead of null 828 // testNoReturn(); // right now we infer the empty type instead of null
760 testArithmeticOperators(); 829 testArithmeticOperators();
761 testOperators(); 830 testOperators();
762 testCompoundOperators1(); 831 testCompoundOperators1();
763 testCompoundOperators2(); 832 testCompoundOperators2();
833 testSetIndexOperator();
834 testInequality();
764 // testFieldInitialization(); // TODO(polux) 835 // testFieldInitialization(); // TODO(polux)
765 testSendWithWrongArity(); 836 testSendWithWrongArity();
766 testDynamicIsAbsorbing(); 837 testDynamicIsAbsorbing();
767 } 838 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/types/concrete_types_inferrer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698