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

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

Issue 11414130: Naive handling of List#[] and List#[]= (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Sync to head Created 7 years, 11 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 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 operator *(x); 151 operator *(x);
152 operator -(x); 152 operator -(x);
153 operator ==(x); 153 operator ==(x);
154 } 154 }
155 abstract class int extends num { } 155 abstract class int extends num { }
156 abstract class double extends num { } 156 abstract class double extends num { }
157 class bool {} 157 class bool {}
158 class String {} 158 class String {}
159 class Object {} 159 class Object {}
160 class Function {} 160 class Function {}
161 abstract class List {} 161 abstract class List<E> {
162 factory List([int length]);
163 E operator [](int index);
164 void operator []=(int index, E value);
165 }
162 abstract class Map {} 166 abstract class Map {}
163 class Closure {} 167 class Closure {}
164 class Null {} 168 class Null {}
165 class Type {} 169 class Type {}
166 class Dynamic_ {} 170 class Dynamic_ {}
167 bool identical(Object a, Object b) {}'''; 171 bool identical(Object a, Object b) {}''';
168 172
169 AnalysisResult analyze(String code, {int maxConcreteTypeSize: 1000}) { 173 AnalysisResult analyze(String code, {int maxConcreteTypeSize: 1000}) {
170 Uri uri = new Uri.fromComponents(scheme: 'source'); 174 Uri uri = new Uri.fromComponents(scheme: 'source');
171 MockCompiler compiler = new MockCompiler( 175 MockCompiler compiler = new MockCompiler(
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 var bar = new A() != 2; 887 var bar = new A() != 2;
884 var baz = new B() != 2; 888 var baz = new B() != 2;
885 foo; bar; baz; 889 foo; bar; baz;
886 } 890 }
887 """; 891 """;
888 AnalysisResult result = analyze(source); 892 AnalysisResult result = analyze(source);
889 result.checkNodeHasType('foo', [result.bool]); 893 result.checkNodeHasType('foo', [result.bool]);
890 result.checkNodeHasType('bar', [result.bool]); 894 result.checkNodeHasType('bar', [result.bool]);
891 result.checkNodeHasType('baz', []); 895 result.checkNodeHasType('baz', []);
892 // TODO(polux): the following result should be [:[null, string]:], see 896 // TODO(polux): the following result should be [:[null, string]:], see
893 // fieldInitialization(). 897 // testFieldInitialization().
894 result.checkFieldHasType('A', 'witness', [result.string]); 898 result.checkFieldHasType('A', 'witness', [result.string]);
895 } 899 }
896 900
897 testFieldInitialization() { 901 testFieldInitialization() {
898 final String source = r""" 902 final String source = r"""
899 class A { 903 class A {
900 var x; 904 var x;
901 var y = 1; 905 var y = 1;
902 } 906 }
903 main () { 907 main () {
904 new A(); 908 new A();
905 } 909 }
906 """; 910 """;
907 AnalysisResult result = analyze(source); 911 AnalysisResult result = analyze(source);
908 result.checkFieldHasType('A', 'x', [result.nullType]); 912 result.checkFieldHasType('A', 'x', [result.nullType]);
909 result.checkFieldHasType('A', 'y', [result.int]); 913 result.checkFieldHasType('A', 'y', [result.int]);
910 } 914 }
911 915
916 testLists() {
917 final String source = r"""
918 main() {
919 new List();
920 var l1 = [1.2];
921 var l2 = [];
922 l1['a'] = 42; // raises an error, so int should not be recorded
923 l1[1] = 'abc';
924 "__dynamic_for_test"[1] = true;
925 var x = l1[1];
926 var y = l2[1];
927 var z = l1['foo'];
928 x; y; z;
929 }""";
930 AnalysisResult result = analyze(source);
931 result.checkNodeHasType('x', [result.double, result.string, result.bool]);
932 result.checkNodeHasType('y', [result.double, result.string, result.bool]);
933 result.checkNodeHasType('z', []);
934 }
935
936 testListWithCapacity() {
937 final String source = r"""
938 main() {
939 var l = new List(10);
940 var x = l[0];
941 x;
942 }""";
943 AnalysisResult result = analyze(source);
944 result.checkNodeHasType('x', [result.nullType]);
945 }
946
947 testEmptyList() {
948 final String source = r"""
949 main() {
950 var l = new List();
951 var x = l[0];
952 x;
953 }""";
954 AnalysisResult result = analyze(source);
955 result.checkNodeHasType('x', []);
956 }
957
912 testSendWithWrongArity() { 958 testSendWithWrongArity() {
913 final String source = r""" 959 final String source = r"""
914 f(x) { } 960 f(x) { }
915 class A { g(x) { } } 961 class A { g(x) { } }
916 main () { 962 main () {
917 var x = f(); 963 var x = f();
918 var y = f(1, 2); 964 var y = f(1, 2);
919 var z = new A().g(); 965 var z = new A().g();
920 var w = new A().g(1, 2); 966 var w = new A().g(1, 2);
921 x; y; z; w; 967 x; y; z; w;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 testOperators(); 1053 testOperators();
1008 testCompoundOperators1(); 1054 testCompoundOperators1();
1009 testCompoundOperators2(); 1055 testCompoundOperators2();
1010 testSetIndexOperator(); 1056 testSetIndexOperator();
1011 testInequality(); 1057 testInequality();
1012 // testFieldInitialization(); // TODO(polux) 1058 // testFieldInitialization(); // TODO(polux)
1013 testSendWithWrongArity(); 1059 testSendWithWrongArity();
1014 testBigTypesWidening1(); 1060 testBigTypesWidening1();
1015 testBigTypesWidening2(); 1061 testBigTypesWidening2();
1016 testDynamicIsAbsorbing(); 1062 testDynamicIsAbsorbing();
1063 testLists();
1064 testListWithCapacity();
1065 testEmptyList();
1017 } 1066 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/types/types.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698