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

Unified Diff: tests/compiler/dart2js/cpa_inference_test.dart

Issue 11272032: Handle compound operators. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add name in TODO 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/types/concrete_types_inferrer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c52058119f23fefd9a31b2997f7584a2283d8163..a8db3d513305e96e2cd3c225c143ef7157e2eaf3 100644
--- a/tests/compiler/dart2js/cpa_inference_test.dart
+++ b/tests/compiler/dart2js/cpa_inference_test.dart
@@ -354,34 +354,40 @@ testGetters() {
var x;
A(this.x);
get y => x;
+ get z => y;
}
main() {
var a = new A(42);
var foo = a.x;
var bar = a.y;
- foo; bar;
+ var baz = a.z;
+ foo; bar; baz;
}
""";
AnalysisResult result = analyze(source);
result.checkNodeHasType('foo', [result.int]);
result.checkNodeHasType('bar', [result.int]);
+ result.checkNodeHasType('baz', [result.int]);
}
testSetters() {
final String source = r"""
class A {
var x;
- A(this.x);
- set y(a) { x = a; }
+ var w;
+ A(this.x, this.w);
+ set y(a) { x = a; z = a; }
+ set z(a) { w = a; }
}
main() {
- var a = new A(42);
+ var a = new A(42, 42);
a.x = 'abc';
a.y = true;
}
""";
AnalysisResult result = analyze(source);
result.checkFieldHasType('A', 'x', [result.int, result.string, result.bool]);
+ result.checkFieldHasType('A', 'w', [result.int, result.bool]);
}
testNamedParameters() {
@@ -521,6 +527,67 @@ testOperators() {
result.checkNodeHasType('y', [result.string]);
}
+testCompoundOperators1() {
+ final String source = r"""
+ class A {
+ operator +(x) => "foo";
+ }
+ main() {
+ var x1 = 1; x1++;
+ var x2 = 1; ++x2;
+ var x3 = new A(); x3++;
+ var x4 = new A(); ++x4;
+
+ x1; x2; x3; x4;
+ }
+ """;
+ AnalysisResult result = analyze(source);
+ result.checkNodeHasType('x1', [result.int]);
+ result.checkNodeHasType('x2', [result.int]);
+ result.checkNodeHasType('x3', [result.string]);
+ result.checkNodeHasType('x4', [result.string]);
+}
+
+
+testCompoundOperators2() {
+ final String source = r"""
+ class A {
+ var xx;
+ var witness1;
+ var witness2;
+
+ A(this.xx);
+ get x { witness1 = "foo"; return xx; }
+ set x(y) { witness2 = "foo"; xx = y; }
+ }
+ main () {
+ var a = new A(1);
+ a.x++;
+ }
+ """;
+ AnalysisResult result = analyze(source);
+ result.checkFieldHasType('A', 'xx', [result.int]);
+ // TODO(polux): the two following results should be {null, string}, see
+ // fieldInitialization().
+ result.checkFieldHasType('A', 'witness1', [result.string]);
+ result.checkFieldHasType('A', 'witness2', [result.string]);
+}
+
+testFieldInitialization() {
+ final String source = r"""
+ class A {
+ var x;
+ var y = 1;
+ }
+ main () {
+ new A();
+ }
+ """;
+ AnalysisResult result = analyze(source);
+ result.checkFieldHasType('A', 'x', [result.nullType]);
+ result.checkFieldHasType('A', 'y', [result.int]);
+}
+
void main() {
testLiterals();
testRedefinition();
@@ -544,4 +611,7 @@ void main() {
// testNoReturn(); // right now we infer the empty type instead of null
testArithmeticOperators();
testOperators();
+ testCompoundOperators1();
+ testCompoundOperators2();
+ // testFieldInitialization(); // TODO(polux)
}
« 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