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 0040e8c41087079f43768bd87b16193d0cf18870..d65c2fe1971554bfefe628413c2437b0748a8398 100644 |
--- a/tests/compiler/dart2js/cpa_inference_test.dart |
+++ b/tests/compiler/dart2js/cpa_inference_test.dart |
@@ -2,6 +2,7 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
+import 'dart:async'; |
import "package:expect/expect.dart"; |
import '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.dart'; |
import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; |
@@ -141,7 +142,7 @@ class AnalysisResult { |
const String CORELIB = r''' |
print(var obj) {} |
- abstract class num { |
+ abstract class num { |
num operator +(num x); |
num operator *(num x); |
num operator -(num x); |
@@ -171,7 +172,7 @@ const String CORELIB = r''' |
class Dynamic_ {} |
bool identical(Object a, Object b) {}'''; |
-AnalysisResult analyze(String code, {int maxConcreteTypeSize: 1000}) { |
+Future<AnalysisResult> analyze(String code, {int maxConcreteTypeSize: 1000}) { |
Uri uri = new Uri(scheme: 'source'); |
MockCompiler compiler = new MockCompiler( |
coreSource: CORELIB, |
@@ -179,8 +180,9 @@ AnalysisResult analyze(String code, {int maxConcreteTypeSize: 1000}) { |
maxConcreteTypeSize: maxConcreteTypeSize); |
compiler.sourceFiles[uri.toString()] = new SourceFile(uri.toString(), code); |
compiler.typesTask.concreteTypesInferrer.testMode = true; |
- compiler.runCompiler(uri); |
- return new AnalysisResult(compiler); |
+ return compiler.runCompiler(uri).then((_) { |
+ return new AnalysisResult(compiler); |
+ }); |
} |
testDynamicBackDoor() { |
@@ -190,8 +192,9 @@ testDynamicBackDoor() { |
x; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasUnknownType('x'); |
+ analyze(source).then((result) { |
+ result.checkNodeHasUnknownType('x'); |
+ }); |
} |
testVariableDeclaration() { |
@@ -203,9 +206,10 @@ testVariableDeclaration() { |
v1; v2; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('v1', [result.nullType]); |
- result.checkNodeHasType('v2', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('v1', [result.nullType]); |
+ result.checkNodeHasType('v2', [result.int]); |
+ }); |
} |
testLiterals() { |
@@ -219,12 +223,13 @@ testLiterals() { |
v1; v2; v3; v4; v5; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('v1', [result.int]); |
- result.checkNodeHasType('v2', [result.double]); |
- result.checkNodeHasType('v3', [result.string]); |
- result.checkNodeHasType('v4', [result.bool]); |
- result.checkNodeHasType('v5', [result.nullType]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('v1', [result.int]); |
+ result.checkNodeHasType('v2', [result.double]); |
+ result.checkNodeHasType('v3', [result.string]); |
+ result.checkNodeHasType('v4', [result.bool]); |
+ result.checkNodeHasType('v5', [result.nullType]); |
+ }); |
} |
testRedefinition() { |
@@ -235,8 +240,9 @@ testRedefinition() { |
foo; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.string]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.string]); |
+ }); |
} |
testIfThenElse() { |
@@ -251,8 +257,9 @@ testIfThenElse() { |
foo; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.string, result.bool]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.string, result.bool]); |
+ }); |
} |
testTernaryIf() { |
@@ -263,8 +270,9 @@ testTernaryIf() { |
foo; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.string, result.bool]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.string, result.bool]); |
+ }); |
} |
testWhile() { |
@@ -281,12 +289,13 @@ testWhile() { |
foo; bar; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType( |
- 'foo', |
- [result.base('A'), result.base('B'), result.base('C')]); |
- // Check that the condition is evaluated. |
- result.checkNodeHasType('bar', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType( |
+ 'foo', |
+ [result.base('A'), result.base('B'), result.base('C')]); |
+ // Check that the condition is evaluated. |
+ result.checkNodeHasType('bar', [result.int]); |
+ }); |
} |
testFor1() { |
@@ -302,10 +311,11 @@ testFor1() { |
foo; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType( |
- 'foo', |
- [result.base('A'), result.base('B'), result.base('C')]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType( |
+ 'foo', |
+ [result.base('A'), result.base('B'), result.base('C')]); |
+ }); |
} |
testFor2() { |
@@ -321,10 +331,11 @@ testFor2() { |
foo; bar; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.base('A'), result.base('B')]); |
- // Check that the condition is evaluated. |
- result.checkNodeHasType('bar', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.base('A'), result.base('B')]); |
+ // Check that the condition is evaluated. |
+ result.checkNodeHasType('bar', [result.int]); |
+ }); |
} |
testFor3() { |
@@ -338,8 +349,9 @@ testFor3() { |
i; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('i', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('i', [result.int]); |
+ }); |
} |
testToplevelVariable() { |
@@ -348,15 +360,16 @@ testToplevelVariable() { |
class A { |
f() => top; |
} |
- main() { |
+ main() { |
var foo = top; |
var bar = new A().f(); |
foo; bar; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.string]); |
- result.checkNodeHasType('bar', [result.string]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.string]); |
+ result.checkNodeHasType('bar', [result.string]); |
+ }); |
} |
testNonRecusiveFunction() { |
@@ -364,8 +377,9 @@ testNonRecusiveFunction() { |
f(x, y) => true ? x : y; |
main() { var foo = f(42, "abc"); foo; } |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.int, result.string]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.int, result.string]); |
+ }); |
} |
testRecusiveFunction() { |
@@ -376,18 +390,20 @@ testRecusiveFunction() { |
} |
main() { var foo = f(42); foo; } |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.int, result.string]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.int, result.string]); |
+ }); |
} |
testMutuallyRecusiveFunction() { |
final String source = r""" |
f() => true ? 42 : g(); |
- g() => true ? "abc" : f(); |
+ g() => true ? "abc" : f(); |
main() { var foo = f(); foo; } |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.int, result.string]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.int, result.string]); |
+ }); |
} |
testSimpleSend() { |
@@ -402,7 +418,7 @@ testSimpleSend() { |
f(x) => 3.14; |
} |
class D { |
- var f; // we check that this field is ignored in calls to dynamic.f() |
+ var f; // we check that this field is ignored in calls to dynamic.f() |
D(this.f); |
} |
main() { |
@@ -412,9 +428,10 @@ testSimpleSend() { |
foo; bar; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.int]); |
- result.checkNodeHasType('bar', [result.int, result.string]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.int]); |
+ result.checkNodeHasType('bar', [result.int, result.string]); |
+ }); |
} |
testSendToClosureField() { |
@@ -429,8 +446,9 @@ testSendToClosureField() { |
foo; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.int]); |
+ }); |
} |
testSendToThis1() { |
@@ -445,8 +463,9 @@ testSendToThis1() { |
foo; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.int]); |
+ }); |
} |
testSendToThis2() { |
@@ -462,8 +481,9 @@ testSendToThis2() { |
x; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.base('B')]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.base('B')]); |
+ }); |
} |
testConstructor() { |
@@ -477,11 +497,12 @@ testConstructor() { |
new A(true, null); |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkFieldHasType('A', 'x', [result.int, result.bool]); |
- result.checkFieldHasType('A', 'y', [result.string, result.nullType]); |
- // TODO(polux): we can be smarter and infer {string} for z |
- result.checkFieldHasType('A', 'z', [result.string, result.nullType]); |
+ analyze(source).then((result) { |
+ result.checkFieldHasType('A', 'x', [result.int, result.bool]); |
+ result.checkFieldHasType('A', 'y', [result.string, result.nullType]); |
+ // TODO(polux): we can be smarter and infer {string} for z |
+ result.checkFieldHasType('A', 'z', [result.string, result.nullType]); |
+ }); |
} |
testGetters() { |
@@ -507,12 +528,13 @@ testGetters() { |
foo; bar; baz; qux; quux; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.int]); |
- result.checkNodeHasType('bar', [result.int]); |
- result.checkNodeHasType('baz', [result.int]); |
- result.checkNodeHasType('qux', []); |
- result.checkNodeHasType('quux', [result.int, result.string]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.int]); |
+ result.checkNodeHasType('bar', [result.int]); |
+ result.checkNodeHasType('baz', [result.int]); |
+ result.checkNodeHasType('qux', []); |
+ result.checkNodeHasType('quux', [result.int, result.string]); |
+ }); |
} |
testSetters() { |
@@ -538,20 +560,21 @@ testSetters() { |
"__dynamic_for_test".y = 3.14; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkFieldHasType('B', 'x', |
- [result.int, // new B(42) |
- result.nullType]); // dynamic.x = null |
- result.checkFieldHasType('A', 'x', |
- [result.int, // new A(42, ...) |
- result.string, // a.x = 'abc' |
- result.bool, // a.y = true |
- result.nullType, // dynamic.x = null |
- result.double]); // dynamic.y = 3.14 |
- result.checkFieldHasType('A', 'w', |
- [result.int, // new A(..., 42) |
- result.bool, // a.y = true |
- result.double]); // dynamic.y = double |
+ analyze(source).then((result) { |
+ result.checkFieldHasType('B', 'x', |
+ [result.int, // new B(42) |
+ result.nullType]); // dynamic.x = null |
+ result.checkFieldHasType('A', 'x', |
+ [result.int, // new A(42, ...) |
+ result.string, // a.x = 'abc' |
+ result.bool, // a.y = true |
+ result.nullType, // dynamic.x = null |
+ result.double]); // dynamic.y = 3.14 |
+ result.checkFieldHasType('A', 'w', |
+ [result.int, // new A(..., 42) |
+ result.bool, // a.y = true |
+ result.double]); // dynamic.y = double |
+ }); |
} |
testOptionalNamedParameters() { |
@@ -616,29 +639,30 @@ testOptionalNamedParameters() { |
test.f3(1, z: 2); // non-existing named parameter |
} |
"""; |
- AnalysisResult result = analyze(source); |
- |
- final foo = result.base('Foo'); |
- final nil = result.nullType; |
- |
- result.checkFieldHasType('A', 'x', [result.int, result.string]); |
- result.checkFieldHasType('A', 'y', [nil]); |
- result.checkFieldHasType('A', 'z', [nil, result.double]); |
- result.checkFieldHasType('A', 'w', [nil, result.bool]); |
- result.checkFieldHasType('Test', 'a', [foo, result.int, result.string]); |
- result.checkFieldHasType('Test', 'b', [foo, nil]); |
- result.checkFieldHasType('Test', 'c', [foo, nil, result.double]); |
- result.checkFieldHasType('Test', 'd', [foo, nil, result.bool]); |
- |
- result.checkFieldHasType('B', 'x', [result.string]); |
- result.checkFieldHasType('B', 'y', [result.bool]); |
- result.checkFieldHasType('Test', 'e', [foo, result.string]); |
- result.checkFieldHasType('Test', 'f', [foo, result.bool]); |
- |
- result.checkFieldHasType('C', 'x', [result.string]); |
- result.checkFieldHasType('C', 'y', [result.bool]); |
- result.checkFieldHasType('Test', 'g', [foo, result.string]); |
- result.checkFieldHasType('Test', 'h', [foo, result.bool]); |
+ analyze(source).then((result) { |
+ |
+ final foo = result.base('Foo'); |
+ final nil = result.nullType; |
+ |
+ result.checkFieldHasType('A', 'x', [result.int, result.string]); |
+ result.checkFieldHasType('A', 'y', [nil]); |
+ result.checkFieldHasType('A', 'z', [nil, result.double]); |
+ result.checkFieldHasType('A', 'w', [nil, result.bool]); |
+ result.checkFieldHasType('Test', 'a', [foo, result.int, result.string]); |
+ result.checkFieldHasType('Test', 'b', [foo, nil]); |
+ result.checkFieldHasType('Test', 'c', [foo, nil, result.double]); |
+ result.checkFieldHasType('Test', 'd', [foo, nil, result.bool]); |
+ |
+ result.checkFieldHasType('B', 'x', [result.string]); |
+ result.checkFieldHasType('B', 'y', [result.bool]); |
+ result.checkFieldHasType('Test', 'e', [foo, result.string]); |
+ result.checkFieldHasType('Test', 'f', [foo, result.bool]); |
+ |
+ result.checkFieldHasType('C', 'x', [result.string]); |
+ result.checkFieldHasType('C', 'y', [result.bool]); |
+ result.checkFieldHasType('Test', 'g', [foo, result.string]); |
+ result.checkFieldHasType('Test', 'h', [foo, result.bool]); |
+ }); |
} |
testOptionalPositionalParameters() { |
@@ -688,24 +712,25 @@ testOptionalPositionalParameters() { |
test.f2(1, 2, 3); // too many arguments |
} |
"""; |
- AnalysisResult result = analyze(source); |
- |
- final foo = result.base('Foo'); |
- final nil = result.nullType; |
- |
- result.checkFieldHasType('A', 'x', [result.int, result.string]); |
- result.checkFieldHasType('A', 'y', [nil, result.bool]); |
- result.checkFieldHasType('A', 'z', [nil, result.double]); |
- result.checkFieldHasType('A', 'w', [nil]); |
- result.checkFieldHasType('Test', 'a', [foo, result.int, result.string]); |
- result.checkFieldHasType('Test', 'b', [foo, nil, result.bool]); |
- result.checkFieldHasType('Test', 'c', [foo, nil, result.double]); |
- result.checkFieldHasType('Test', 'd', [foo, nil]); |
- |
- result.checkFieldHasType('B', 'x', [result.string]); |
- result.checkFieldHasType('B', 'y', [result.bool]); |
- result.checkFieldHasType('Test', 'e', [foo, result.string]); |
- result.checkFieldHasType('Test', 'f', [foo, result.bool]); |
+ analyze(source).then((result) { |
+ |
+ final foo = result.base('Foo'); |
+ final nil = result.nullType; |
+ |
+ result.checkFieldHasType('A', 'x', [result.int, result.string]); |
+ result.checkFieldHasType('A', 'y', [nil, result.bool]); |
+ result.checkFieldHasType('A', 'z', [nil, result.double]); |
+ result.checkFieldHasType('A', 'w', [nil]); |
+ result.checkFieldHasType('Test', 'a', [foo, result.int, result.string]); |
+ result.checkFieldHasType('Test', 'b', [foo, nil, result.bool]); |
+ result.checkFieldHasType('Test', 'c', [foo, nil, result.double]); |
+ result.checkFieldHasType('Test', 'd', [foo, nil]); |
+ |
+ result.checkFieldHasType('B', 'x', [result.string]); |
+ result.checkFieldHasType('B', 'y', [result.bool]); |
+ result.checkFieldHasType('Test', 'e', [foo, result.string]); |
+ result.checkFieldHasType('Test', 'f', [foo, result.bool]); |
+ }); |
} |
testListLiterals() { |
@@ -720,10 +745,11 @@ testListLiterals() { |
x; y; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.list]); |
- result.checkNodeHasType('y', [result.list]); |
- result.checkFieldHasType('A', 'x', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.list]); |
+ result.checkNodeHasType('y', [result.list]); |
+ result.checkFieldHasType('A', 'x', [result.int]); |
+ }); |
} |
testMapLiterals() { |
@@ -738,10 +764,11 @@ testMapLiterals() { |
x; y; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.map]); |
- result.checkNodeHasType('y', [result.map]); |
- result.checkFieldHasType('A', 'x', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.map]); |
+ result.checkNodeHasType('y', [result.map]); |
+ result.checkFieldHasType('A', 'x', [result.int]); |
+ }); |
} |
testReturn() { |
@@ -754,9 +781,10 @@ testReturn() { |
x; y; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.int, result.string]); |
- result.checkNodeHasType('y', [result.nullType]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.int, result.string]); |
+ result.checkNodeHasType('y', [result.nullType]); |
+ }); |
} |
testNoReturn() { |
@@ -769,9 +797,10 @@ testNoReturn() { |
x; y; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.int, result.nullType]); |
- result.checkNodeHasType('y', [result.nullType]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.int, result.nullType]); |
+ result.checkNodeHasType('y', [result.nullType]); |
+ }); |
} |
testArithmeticOperators() { |
@@ -794,19 +823,20 @@ testArithmeticOperators() { |
}"""; |
} |
for (String op in ['+', '*', '-']) { |
- AnalysisResult result = analyze(source(op)); |
- result.checkNodeHasType('a', [result.int]); |
- result.checkNodeHasType('b', [result.num]); |
- result.checkNodeHasType('c', [result.num]); |
- result.checkNodeHasType('d', [result.double]); |
- result.checkNodeHasType('e', [result.num]); |
- result.checkNodeHasType('f', [result.num]); |
- result.checkNodeHasType('g', [result.num]); |
- result.checkNodeHasType('h', [result.num]); |
- result.checkNodeHasType('i', [result.int]); |
- result.checkNodeHasType('j', [result.int]); |
- result.checkNodeHasType('k', [result.double]); |
- result.checkNodeHasType('l', [result.double]); |
+ analyze(source(op)).then((result) { |
+ result.checkNodeHasType('a', [result.int]); |
+ result.checkNodeHasType('b', [result.num]); |
+ result.checkNodeHasType('c', [result.num]); |
+ result.checkNodeHasType('d', [result.double]); |
+ result.checkNodeHasType('e', [result.num]); |
+ result.checkNodeHasType('f', [result.num]); |
+ result.checkNodeHasType('g', [result.num]); |
+ result.checkNodeHasType('h', [result.num]); |
+ result.checkNodeHasType('i', [result.int]); |
+ result.checkNodeHasType('j', [result.int]); |
+ result.checkNodeHasType('k', [result.double]); |
+ result.checkNodeHasType('l', [result.double]); |
+ }); |
} |
} |
@@ -822,11 +852,12 @@ testBooleanOperators() { |
}"""; |
} |
for (String op in ['&&', '||']) { |
- AnalysisResult result = analyze(source(op)); |
- result.checkNodeHasType('a', [result.bool]); |
- result.checkNodeHasType('b', [result.bool]); |
- result.checkNodeHasType('c', [result.bool]); |
- result.checkNodeHasType('d', [result.bool]); |
+ analyze(source(op)).then((result) { |
+ result.checkNodeHasType('a', [result.bool]); |
+ result.checkNodeHasType('b', [result.bool]); |
+ result.checkNodeHasType('c', [result.bool]); |
+ result.checkNodeHasType('d', [result.bool]); |
+ }); |
} |
} |
@@ -842,9 +873,10 @@ testOperators() { |
x; y; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.int]); |
- result.checkNodeHasType('y', [result.string]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.int]); |
+ result.checkNodeHasType('y', [result.string]); |
+ }); |
} |
testSetIndexOperator() { |
@@ -859,10 +891,11 @@ testSetIndexOperator() { |
x; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.string]); |
- result.checkFieldHasType('A', 'witness1', [result.int, result.nullType]); |
- result.checkFieldHasType('A', 'witness2', [result.string, result.nullType]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.string]); |
+ result.checkFieldHasType('A', 'witness1', [result.int, result.nullType]); |
+ result.checkFieldHasType('A', 'witness2', [result.string, result.nullType]); |
+ }); |
} |
testCompoundOperators1() { |
@@ -887,13 +920,14 @@ testCompoundOperators1() { |
x1; x2; x3; x4; x5; x6; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x1', [result.int]); |
- result.checkNodeHasType('x2', [result.int]); |
- result.checkNodeHasType('x3', [result.int]); |
- result.checkNodeHasType('x4', [result.string]); |
- result.checkNodeHasType('x5', [result.string]); |
- result.checkNodeHasType('x6', [result.string]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x1', [result.int]); |
+ result.checkNodeHasType('x2', [result.int]); |
+ result.checkNodeHasType('x3', [result.int]); |
+ result.checkNodeHasType('x4', [result.string]); |
+ result.checkNodeHasType('x5', [result.string]); |
+ result.checkNodeHasType('x6', [result.string]); |
+ }); |
} |
@@ -916,16 +950,17 @@ testCompoundOperators2() { |
main () { |
var a = new A(1, 1); |
a.x++; |
- a.y++; |
+ a.y++; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkFieldHasType('A', 'xx', [result.int]); |
- result.checkFieldHasType('A', 'yy', [result.int]); |
- result.checkFieldHasType('A', 'witness1', [result.string, result.nullType]); |
- result.checkFieldHasType('A', 'witness2', [result.string, result.nullType]); |
- result.checkFieldHasType('A', 'witness3', [result.string, result.nullType]); |
- result.checkFieldHasType('A', 'witness4', [result.string, result.nullType]); |
+ analyze(source).then((result) { |
+ result.checkFieldHasType('A', 'xx', [result.int]); |
+ result.checkFieldHasType('A', 'yy', [result.int]); |
+ result.checkFieldHasType('A', 'witness1', [result.string, result.nullType]); |
+ result.checkFieldHasType('A', 'witness2', [result.string, result.nullType]); |
+ result.checkFieldHasType('A', 'witness3', [result.string, result.nullType]); |
+ result.checkFieldHasType('A', 'witness4', [result.string, result.nullType]); |
+ }); |
} |
testInequality() { |
@@ -944,11 +979,12 @@ testInequality() { |
foo; bar; baz; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.bool]); |
- result.checkNodeHasType('bar', [result.bool]); |
- result.checkNodeHasType('baz', []); |
- result.checkFieldHasType('A', 'witness', [result.string, result.nullType]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.bool]); |
+ result.checkNodeHasType('bar', [result.bool]); |
+ result.checkNodeHasType('baz', []); |
+ result.checkFieldHasType('A', 'witness', [result.string, result.nullType]); |
+ }); |
} |
testFieldInitialization1() { |
@@ -964,10 +1000,11 @@ testFieldInitialization1() { |
new B(); |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkFieldHasType('A', 'x', [result.nullType]); |
- result.checkFieldHasType('A', 'y', [result.int]); |
- result.checkFieldHasType('B', 'z', [result.string]); |
+ analyze(source).then((result) { |
+ result.checkFieldHasType('A', 'x', [result.nullType]); |
+ result.checkFieldHasType('A', 'y', [result.int]); |
+ result.checkFieldHasType('B', 'z', [result.string]); |
+ }); |
} |
testFieldInitialization2() { |
@@ -980,8 +1017,9 @@ testFieldInitialization2() { |
new A(); |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkFieldHasType('A', 'x', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkFieldHasType('A', 'x', [result.int]); |
+ }); |
} |
testFieldInitialization3() { |
@@ -1001,15 +1039,16 @@ testFieldInitialization3() { |
foo; bar; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- // checks that B.B is set as a reader of A.x |
- result.checkFieldHasType('B', 'x', [result.nullType, result.string]); |
- // checks that B.B is set as a caller of f |
- result.checkFieldHasType('B', 'y', [result.nullType, result.string]); |
- // checks that readers of x are notified by changes in x's type |
- result.checkNodeHasType('foo', [result.nullType, result.string]); |
- // checks that readers of y are notified by changes in y's type |
- result.checkNodeHasType('bar', [result.nullType, result.string]); |
+ analyze(source).then((result) { |
+ // checks that B.B is set as a reader of A.x |
+ result.checkFieldHasType('B', 'x', [result.nullType, result.string]); |
+ // checks that B.B is set as a caller of f |
+ result.checkFieldHasType('B', 'y', [result.nullType, result.string]); |
+ // checks that readers of x are notified by changes in x's type |
+ result.checkNodeHasType('foo', [result.nullType, result.string]); |
+ // checks that readers of y are notified by changes in y's type |
+ result.checkNodeHasType('bar', [result.nullType, result.string]); |
+ }); |
} |
testLists() { |
@@ -1026,10 +1065,11 @@ testLists() { |
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', []); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.double, result.string, result.bool]); |
+ result.checkNodeHasType('y', [result.double, result.string, result.bool]); |
+ result.checkNodeHasType('z', []); |
+ }); |
} |
testListWithCapacity() { |
@@ -1039,8 +1079,9 @@ testListWithCapacity() { |
var x = l[0]; |
x; |
}"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.nullType]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.nullType]); |
+ }); |
} |
testEmptyList() { |
@@ -1050,8 +1091,9 @@ testEmptyList() { |
var x = l[0]; |
x; |
}"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', []); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', []); |
+ }); |
} |
testSendWithWrongArity() { |
@@ -1066,11 +1108,12 @@ testSendWithWrongArity() { |
x; y; z; w; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', []); |
- result.checkNodeHasType('y', []); |
- result.checkNodeHasType('z', []); |
- result.checkNodeHasType('w', []); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', []); |
+ result.checkNodeHasType('y', []); |
+ result.checkNodeHasType('z', []); |
+ result.checkNodeHasType('w', []); |
+ }); |
} |
testBigTypesWidening1() { |
@@ -1083,9 +1126,10 @@ testBigTypesWidening1() { |
x; y; |
} |
"""; |
- AnalysisResult result = analyze(source, maxConcreteTypeSize: 2); |
- result.checkNodeHasType('x', [result.int, result.string]); |
- result.checkNodeHasUnknownType('y'); |
+ analyze(source, maxConcreteTypeSize: 2).then((result) { |
+ result.checkNodeHasType('x', [result.int, result.string]); |
+ result.checkNodeHasUnknownType('y'); |
+ }); |
} |
testBigTypesWidening2() { |
@@ -1101,9 +1145,10 @@ testBigTypesWidening2() { |
a.y = true; |
} |
"""; |
- AnalysisResult result = analyze(source, maxConcreteTypeSize: 2); |
- result.checkFieldHasType('A', 'x', [result.int, result.string]); |
- result.checkFieldHasUknownType('A', 'y'); |
+ analyze(source, maxConcreteTypeSize: 2).then((result) { |
+ result.checkFieldHasType('A', 'x', [result.int, result.string]); |
+ result.checkFieldHasUknownType('A', 'y'); |
+ }); |
} |
testDynamicIsAbsorbing() { |
@@ -1118,8 +1163,9 @@ testDynamicIsAbsorbing() { |
x; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasUnknownType('x'); |
+ analyze(source).then((result) { |
+ result.checkNodeHasUnknownType('x'); |
+ }); |
} |
testJsCall() { |
@@ -1152,19 +1198,20 @@ testJsCall() { |
a; b; c; d; e; f; g; h; i; j; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasUnknownType('a'); |
- result.checkNodeHasUnknownType('b'); |
- // TODO(polux): Fix this test. |
- // result.checkNodeHasType('c', [result.nullType, result.list]); |
- result.checkNodeHasType('d', [result.nullType, result.string]); |
- result.checkNodeHasType('e', [result.nullType, result.int]); |
- result.checkNodeHasType('f', [result.nullType, result.double]); |
- result.checkNodeHasType('g', [result.nullType, result.num]); |
- result.checkNodeHasType('h', [result.nullType, result.bool]); |
- result.checkNodeHasType('i', [result.nullType, result.base('B'), |
- result.base('BB'), result.base('C')]); |
- result.checkNodeHasType('j', [result.nullType]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasUnknownType('a'); |
+ result.checkNodeHasUnknownType('b'); |
+ // TODO(polux): Fix this test. |
+ // result.checkNodeHasType('c', [result.nullType, result.list]); |
+ result.checkNodeHasType('d', [result.nullType, result.string]); |
+ result.checkNodeHasType('e', [result.nullType, result.int]); |
+ result.checkNodeHasType('f', [result.nullType, result.double]); |
+ result.checkNodeHasType('g', [result.nullType, result.num]); |
+ result.checkNodeHasType('h', [result.nullType, result.bool]); |
+ result.checkNodeHasType('i', [result.nullType, result.base('B'), |
+ result.base('BB'), result.base('C')]); |
+ result.checkNodeHasType('j', [result.nullType]); |
+ }); |
} |
testIsCheck() { |
@@ -1174,8 +1221,9 @@ testIsCheck() { |
x; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.bool]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.bool]); |
+ }); |
} |
testSeenClasses() { |
@@ -1201,8 +1249,9 @@ testSeenClasses() { |
foo; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('foo', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('foo', [result.int]); |
+ }); |
} |
testIntDoubleNum() { |
@@ -1214,10 +1263,11 @@ testIntDoubleNum() { |
a; b; c; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('a', [result.int]); |
- result.checkNodeHasType('b', [result.double]); |
- result.checkNodeHasType('c', [result.num]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('a', [result.int]); |
+ result.checkNodeHasType('b', [result.double]); |
+ result.checkNodeHasType('c', [result.num]); |
+ }); |
} |
testConcreteTypeToTypeMask() { |
@@ -1233,46 +1283,47 @@ testConcreteTypeToTypeMask() { |
new D(); |
} |
"""; |
- AnalysisResult result = analyze(source); |
+ analyze(source).then((result) { |
- convert(ConcreteType type) { |
- return result.compiler.typesTask.concreteTypesInferrer |
- .concreteTypeToTypeMask(type); |
- } |
+ convert(ConcreteType type) { |
+ return result.compiler.typesTask.concreteTypesInferrer |
+ .concreteTypeToTypeMask(type); |
+ } |
- final nullSingleton = |
- result.compiler.typesTask.concreteTypesInferrer.singletonConcreteType( |
- new NullBaseType()); |
+ final nullSingleton = |
+ result.compiler.typesTask.concreteTypesInferrer.singletonConcreteType( |
+ new NullBaseType()); |
- singleton(ClassElement element) { |
- return result.compiler.typesTask.concreteTypesInferrer |
- .singletonConcreteType(new ClassBaseType(element)); |
- } |
+ singleton(ClassElement element) { |
+ return result.compiler.typesTask.concreteTypesInferrer |
+ .singletonConcreteType(new ClassBaseType(element)); |
+ } |
- ClassElement a = findElement(result.compiler, 'A'); |
- ClassElement b = findElement(result.compiler, 'B'); |
- ClassElement c = findElement(result.compiler, 'C'); |
- ClassElement d = findElement(result.compiler, 'D'); |
+ ClassElement a = findElement(result.compiler, 'A'); |
+ ClassElement b = findElement(result.compiler, 'B'); |
+ ClassElement c = findElement(result.compiler, 'C'); |
+ ClassElement d = findElement(result.compiler, 'D'); |
- for (ClassElement cls in [a, b, c, d]) { |
- Expect.equals(convert(singleton(cls)), |
- new TypeMask.nonNullExact(cls.rawType)); |
- } |
+ for (ClassElement cls in [a, b, c, d]) { |
+ Expect.equals(convert(singleton(cls)), |
+ new TypeMask.nonNullExact(cls.rawType)); |
+ } |
- for (ClassElement cls in [a, b, c, d]) { |
- Expect.equals(convert(singleton(cls).union(nullSingleton)), |
- new TypeMask.exact(cls.rawType)); |
- } |
+ for (ClassElement cls in [a, b, c, d]) { |
+ Expect.equals(convert(singleton(cls).union(nullSingleton)), |
+ new TypeMask.exact(cls.rawType)); |
+ } |
- Expect.equals(convert(singleton(a).union(singleton(b))), |
- new TypeMask.nonNullSubclass(a.rawType)); |
+ Expect.equals(convert(singleton(a).union(singleton(b))), |
+ new TypeMask.nonNullSubclass(a.rawType)); |
- Expect.equals(convert(singleton(a).union(singleton(b)).union(nullSingleton)), |
- new TypeMask.subclass(a.rawType)); |
+ Expect.equals(convert(singleton(a).union(singleton(b)).union(nullSingleton)), |
+ new TypeMask.subclass(a.rawType)); |
- Expect.equals( |
- convert(singleton(b).union(singleton(d))).simplify(result.compiler), |
- new TypeMask.nonNullSubtype(a.rawType)); |
+ Expect.equals( |
+ convert(singleton(b).union(singleton(d))).simplify(result.compiler), |
+ new TypeMask.nonNullSubtype(a.rawType)); |
+ }); |
} |
testSelectors() { |
@@ -1298,45 +1349,46 @@ testSelectors() { |
new Z().foo(); |
} |
"""; |
- AnalysisResult result = analyze(source); |
+ analyze(source).then((result) { |
- inferredType(Selector selector) { |
- return result.compiler.typesTask.concreteTypesInferrer |
- .getTypeOfSelector(selector); |
- } |
+ inferredType(Selector selector) { |
+ return result.compiler.typesTask.concreteTypesInferrer |
+ .getTypeOfSelector(selector); |
+ } |
- ClassElement abc = findElement(result.compiler, 'ABC'); |
- ClassElement bc = findElement(result.compiler, 'BC'); |
- ClassElement a = findElement(result.compiler, 'A'); |
- ClassElement b = findElement(result.compiler, 'B'); |
- ClassElement c = findElement(result.compiler, 'C'); |
- ClassElement xy = findElement(result.compiler, 'XY'); |
- ClassElement x = findElement(result.compiler, 'X'); |
- ClassElement y = findElement(result.compiler, 'Y'); |
- ClassElement z = findElement(result.compiler, 'Z'); |
- |
- Selector foo = new Selector.call(buildSourceString("foo"), null, 0); |
- |
- Expect.equals( |
- inferredType(foo).simplify(result.compiler), |
- new TypeMask.nonNullSubclass(abc.rawType)); |
- Expect.equals( |
- inferredType(new TypedSelector.subclass(x.rawType, foo)), |
- new TypeMask.nonNullExact(b.rawType)); |
- Expect.equals( |
- inferredType(new TypedSelector.subclass(y.rawType, foo)), |
- new TypeMask.nonNullExact(c.rawType)); |
- Expect.equals( |
- inferredType(new TypedSelector.subclass(z.rawType, foo)), |
- new TypeMask.nonNullExact(a.rawType)); |
- Expect.equals( |
- inferredType(new TypedSelector.subclass( |
- xy.rawType, foo)).simplify(result.compiler), |
- new TypeMask.nonNullSubclass(bc.rawType)); |
- |
- Selector bar = new Selector.call(buildSourceString("bar"), null, 0); |
- |
- Expect.isNull(inferredType(bar)); |
+ ClassElement abc = findElement(result.compiler, 'ABC'); |
+ ClassElement bc = findElement(result.compiler, 'BC'); |
+ ClassElement a = findElement(result.compiler, 'A'); |
+ ClassElement b = findElement(result.compiler, 'B'); |
+ ClassElement c = findElement(result.compiler, 'C'); |
+ ClassElement xy = findElement(result.compiler, 'XY'); |
+ ClassElement x = findElement(result.compiler, 'X'); |
+ ClassElement y = findElement(result.compiler, 'Y'); |
+ ClassElement z = findElement(result.compiler, 'Z'); |
+ |
+ Selector foo = new Selector.call(buildSourceString("foo"), null, 0); |
+ |
+ Expect.equals( |
+ inferredType(foo).simplify(result.compiler), |
+ new TypeMask.nonNullSubclass(abc.rawType)); |
+ Expect.equals( |
+ inferredType(new TypedSelector.subclass(x.rawType, foo)), |
+ new TypeMask.nonNullExact(b.rawType)); |
+ Expect.equals( |
+ inferredType(new TypedSelector.subclass(y.rawType, foo)), |
+ new TypeMask.nonNullExact(c.rawType)); |
+ Expect.equals( |
+ inferredType(new TypedSelector.subclass(z.rawType, foo)), |
+ new TypeMask.nonNullExact(a.rawType)); |
+ Expect.equals( |
+ inferredType(new TypedSelector.subclass( |
+ xy.rawType, foo)).simplify(result.compiler), |
+ new TypeMask.nonNullSubclass(bc.rawType)); |
+ |
+ Selector bar = new Selector.call(buildSourceString("bar"), null, 0); |
+ |
+ Expect.isNull(inferredType(bar)); |
+ }); |
} |
testMixins() { |
@@ -1358,11 +1410,12 @@ testMixins() { |
x; y; z; w; |
} |
"""; |
- AnalysisResult result = analyze(source); |
- result.checkNodeHasType('x', [result.string]); |
- result.checkNodeHasType('y', [result.string]); |
- result.checkNodeHasType('z', [result.int]); |
- result.checkNodeHasType('w', [result.int]); |
+ analyze(source).then((result) { |
+ result.checkNodeHasType('x', [result.string]); |
+ result.checkNodeHasType('y', [result.string]); |
+ result.checkNodeHasType('z', [result.int]); |
+ result.checkNodeHasType('w', [result.int]); |
+ }); |
} |
void main() { |