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

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

Issue 10908068: Better tracking of provided types at call sites (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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/call_site_type_inferer_test.dart
diff --git a/tests/compiler/dart2js/call_site_type_inferer_test.dart b/tests/compiler/dart2js/call_site_type_inferer_test.dart
index a79801073d1348d2dd23bbfd194c3d87574ec5cc..d6ecc98b8d3f6e883af4776c255f244fbe3da79a 100644
--- a/tests/compiler/dart2js/call_site_type_inferer_test.dart
+++ b/tests/compiler/dart2js/call_site_type_inferer_test.dart
@@ -6,6 +6,7 @@
#import("../../../lib/compiler/implementation/js_backend/js_backend.dart");
#import("../../../lib/compiler/implementation/ssa/ssa.dart");
+#import("../../../lib/compiler/implementation/scanner/scannerlib.dart");
#import('compiler_helper.dart');
#import('parser_helper.dart');
@@ -140,14 +141,66 @@ const String TEST_13 = @"""
}
""";
-void runTest(String test, [List<HType> expectedTypes = null]) {
+const String TEST_14 = @"""
+ class A {
+ x(p1, [p2 = "s"]) => 1;
+ }
+ main() {
+ new A().x(1);
+ }
+""";
+
+const String TEST_15 = @"""
+ class A {
+ x(p1, [p2 = true]) => 1;
+ }
+ f(p) => p.a("x");
+ main() {
+ new A().x("x");
+ new A().x("x", false);
+ f(null);
+ //new A().x(1, p3: "x");
kasperl 2012/09/04 09:18:45 Hmm.
Søren Gjesse 2012/09/04 14:55:07 Removed.
+ }
+""";
+
+const String TEST_16 = @"""
+ class A {
+ x(p1, [p2 = 1, p3 = "s"]) => 1;
+ }
+ main() {
+ new A().x(1);
+ new A().x(1, 2);
+ new A().x(1, 2, "x");
+ new A().x(1, p2: 2);
+ new A().x(1, p3: "x");
+ new A().x(1, p3: "x", p2: 2);
+ new A().x(1, p2: 2, p3: "x");
+ }
+""";
+
+const String TEST_17 = @"""
+ class A {
+ x(p1, [p2 = 1, p3 = "s"]) => 1;
+ }
+ main() {
+ new A().x(1, true, 1.1);
+ new A().x(1, false, 2.2);
+ new A().x(1, p3: 3.3, p2: true);
+ new A().x(1, p2: false, p3: 4.4);
+ }
+""";
+
+void runTest(String test,
+ [List<HType> expectedTypes,
+ OptionalParameterTypes defaultTypes]) {
compileAndFind(
test,
'A',
'x',
(backend, x) {
- HTypeList types = backend.optimisticParameterTypes(x);
+ HTypeList types = backend.optimisticParameterTypes(x, defaultTypes);
if (expectedTypes != null) {
+ Expect.isFalse(types.allUnknown);
Expect.listEquals(expectedTypes, types.types);
} else {
Expect.isTrue(types.allUnknown);
@@ -156,6 +209,8 @@ void runTest(String test, [List<HType> expectedTypes = null]) {
}
void test() {
+ OptionalParameterTypes defaultTypes;
+
runTest(TEST_1, [HType.STRING]);
runTest(TEST_2, [HType.INTEGER]);
runTest(TEST_3, [HType.INTEGER]);
@@ -167,8 +222,30 @@ void test() {
runTest(TEST_9, [HType.INTEGER, HType.INTEGER]);
runTest(TEST_10);
runTest(TEST_11);
- runTest(TEST_12);
+
+ defaultTypes = new OptionalParameterTypes(1);
+ defaultTypes.insert(0, const SourceString("p2"), HType.INTEGER);
+ runTest(TEST_12, [HType.STRING, HType.INTEGER], defaultTypes);
+
runTest(TEST_13, [HType.NUMBER]);
+
+ defaultTypes = new OptionalParameterTypes(1);
+ defaultTypes.insert(0, const SourceString("p2"), HType.STRING);
+ runTest(TEST_14, [HType.INTEGER, HType.STRING], defaultTypes);
+
+ defaultTypes = new OptionalParameterTypes(1);
+ defaultTypes.insert(0, const SourceString("p2"), HType.BOOLEAN);
+ runTest(TEST_15, [HType.STRING, HType.BOOLEAN], defaultTypes);
+
+ defaultTypes = new OptionalParameterTypes(2);
+ defaultTypes.insert(0, const SourceString("p2"), HType.INTEGER);
+ defaultTypes.insert(1, const SourceString("p3"), HType.STRING);
+ runTest(TEST_16, [HType.INTEGER, HType.INTEGER, HType.STRING], defaultTypes);
+
+ defaultTypes = new OptionalParameterTypes(2);
+ defaultTypes.insert(0, const SourceString("p2"), HType.INTEGER);
+ defaultTypes.insert(1, const SourceString("p3"), HType.STRING);
+ runTest(TEST_17, [HType.INTEGER, HType.BOOLEAN, HType.DOUBLE], defaultTypes);
}
void main() {

Powered by Google App Engine
This is Rietveld 408576698