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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tests/compiler/dart2js/cpa_inference_test.dart
diff --git a/tests/compiler/dart2js/cpa_inference_test.dart b/tests/compiler/dart2js/cpa_inference_test.dart
index 5d4ffff8cfaa28721076688f3cbffe946b9b3dce..ae905932a7237ccafc2750dfc47561f51a930cfb 100644
--- a/tests/compiler/dart2js/cpa_inference_test.dart
+++ b/tests/compiler/dart2js/cpa_inference_test.dart
@@ -158,7 +158,11 @@ const String CORELIB = r'''
class String {}
class Object {}
class Function {}
- abstract class List {}
+ abstract class List<E> {
+ factory List([int length]);
+ E operator [](int index);
+ void operator []=(int index, E value);
+ }
abstract class Map {}
class Closure {}
class Null {}
@@ -890,7 +894,7 @@ testInequality() {
result.checkNodeHasType('bar', [result.bool]);
result.checkNodeHasType('baz', []);
// TODO(polux): the following result should be [:[null, string]:], see
- // fieldInitialization().
+ // testFieldInitialization().
result.checkFieldHasType('A', 'witness', [result.string]);
}
@@ -909,6 +913,48 @@ testFieldInitialization() {
result.checkFieldHasType('A', 'y', [result.int]);
}
+testLists() {
+ final String source = r"""
+ main() {
+ new List();
+ var l1 = [1.2];
+ var l2 = [];
+ l1['a'] = 42; // raises an error, so int should not be recorded
+ l1[1] = 'abc';
+ "__dynamic_for_test"[1] = true;
+ var x = l1[1];
+ var y = l2[1];
+ var z = l1['foo'];
+ x; y; z;
+ }""";
+ AnalysisResult result = analyze(source);
+ result.checkNodeHasType('x', [result.double, result.string, result.bool]);
+ result.checkNodeHasType('y', [result.double, result.string, result.bool]);
+ result.checkNodeHasType('z', []);
+}
+
+testListWithCapacity() {
+ final String source = r"""
+ main() {
+ var l = new List(10);
+ var x = l[0];
+ x;
+ }""";
+ AnalysisResult result = analyze(source);
+ result.checkNodeHasType('x', [result.nullType]);
+}
+
+testEmptyList() {
+ final String source = r"""
+ main() {
+ var l = new List();
+ var x = l[0];
+ x;
+ }""";
+ AnalysisResult result = analyze(source);
+ result.checkNodeHasType('x', []);
+}
+
testSendWithWrongArity() {
final String source = r"""
f(x) { }
@@ -1014,4 +1060,7 @@ void main() {
testBigTypesWidening1();
testBigTypesWidening2();
testDynamicIsAbsorbing();
+ testLists();
+ testListWithCapacity();
+ testEmptyList();
}
« 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