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 99558b77a36ee94a952fbe3e558c341ba82ce532..ea8ffce300edb1567e2ce0adfa7e2aacf0ef89d6 100644 |
--- a/tests/compiler/dart2js/cpa_inference_test.dart |
+++ b/tests/compiler/dart2js/cpa_inference_test.dart |
@@ -511,15 +511,27 @@ testSetters() { |
result.double]); // dynamic.y = double |
} |
-testNamedParameters() { |
+testOptionalNamedParameters() { |
karlklose
2013/01/15 09:54:51
Perhaps you should add a few tests using methods i
polux
2013/01/17 09:14:27
Done.
|
final String source = r""" |
class A { |
var x, y, z, w; |
A(this.x, {this.y, this.z, this.w}); |
} |
+ class B { |
+ var x, y; |
+ B(this.x, {this.y}); |
+ } |
+ class C { |
+ var x, y; |
+ C(this.x, {this.y}); |
+ } |
main() { |
new A(42); |
new A('abc', w: true, z: 42.0); |
+ new B('abc', y: true); |
+ new B(1, 2); // too many positional arguments |
+ new C('abc', y: true); |
+ new C(1, z: 2); // non-existing named parameter |
} |
"""; |
AnalysisResult result = analyze(source); |
@@ -527,6 +539,36 @@ testNamedParameters() { |
result.checkFieldHasType('A', 'y', [new NullBaseType()]); |
result.checkFieldHasType('A', 'z', [new NullBaseType(), result.double]); |
result.checkFieldHasType('A', 'w', [new NullBaseType(), result.bool]); |
+ result.checkFieldHasType('B', 'x', [result.string]); |
+ result.checkFieldHasType('B', 'y', [result.bool]); |
+ result.checkFieldHasType('C', 'x', [result.string]); |
+ result.checkFieldHasType('C', 'y', [result.bool]); |
+} |
+ |
+testOptionalPositionalParameters() { |
+ final String source = r""" |
+ class A { |
+ var x, y, z, w; |
+ A(this.x, [this.y, this.z, this.w]); |
+ } |
+ class B { |
+ var x, y; |
+ B(this.x, [this.y]); |
+ } |
+ main() { |
+ new A(42); |
+ new A('abc', true, 42.0); |
+ new B('a', true); |
+ new B(1, 2, 3); // too many arguments |
+ } |
+ """; |
+ AnalysisResult result = analyze(source); |
+ result.checkFieldHasType('A', 'x', [result.int, result.string]); |
+ result.checkFieldHasType('A', 'y', [new NullBaseType(), result.bool]); |
+ result.checkFieldHasType('A', 'z', [new NullBaseType(), result.double]); |
+ result.checkFieldHasType('A', 'w', [new NullBaseType()]); |
+ result.checkFieldHasType('B', 'x', [result.string]); |
+ result.checkFieldHasType('B', 'y', [result.bool]); |
} |
testListLiterals() { |
@@ -861,7 +903,8 @@ void main() { |
testConstructor(); |
testGetters(); |
testSetters(); |
- testNamedParameters(); |
+ testOptionalNamedParameters(); |
+ testOptionalPositionalParameters(); |
testListLiterals(); |
testMapLiterals(); |
testReturn(); |