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

Unified Diff: frog/tests/leg/src/TypeCheckerTest.dart

Issue 9835007: Typecheck constructor calls. I'm pretty sure about the call to (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests to TypeCheckerTest Created 8 years, 9 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
« no previous file with comments | « no previous file | lib/compiler/implementation/typechecker.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/tests/leg/src/TypeCheckerTest.dart
diff --git a/frog/tests/leg/src/TypeCheckerTest.dart b/frog/tests/leg/src/TypeCheckerTest.dart
index 9d6c972bd1506ce63f8c9b37f2ed578bb40f2467..331645676b5bd5495e8c295f960bf26a08bdd603 100644
--- a/frog/tests/leg/src/TypeCheckerTest.dart
+++ b/frog/tests/leg/src/TypeCheckerTest.dart
@@ -22,6 +22,8 @@ main() {
testFor,
testWhile,
testOperators,
+ testConstructorInvocationArgumentCount,
+ testConstructorInvocationArgumentTypes,
testMethodInvocationArgumentCount,
testMethodInvocations,
testControlFlow,
@@ -132,6 +134,41 @@ testOperators() {
}
}
+void testConstructorInvocationArgumentCount() {
+ compiler.parseScript("""
+ class C1 { C1(x, y); }
+ class C2 { C2(int x, int y); }
+ """);
+ // calls to untyped constructor C1
+ analyze("new C1(1, 2);");
+ analyze("new C1();",
karlklose 2012/03/30 08:55:31 I think most of these would fit on one line (also
polux 2012/03/30 09:01:28 Done, I thought the layout of the other methods wa
+ MessageKind.MISSING_ARGUMENT);
+ analyze("new C1(1);",
+ MessageKind.MISSING_ARGUMENT);
+ analyze("new C1(1, 2, 3);",
+ MessageKind.ADDITIONAL_ARGUMENT);
+ analyze("new C1(1, 2);");
+ // calls to typed constructor C2
+ analyze("new C1();",
karlklose 2012/03/30 08:55:31 new C1() -> new C2() (also in l. 154 and 156). Ple
polux 2012/03/30 09:01:28 Thanks for catching that.
+ MessageKind.MISSING_ARGUMENT);
+ analyze("new C1(1);",
+ MessageKind.MISSING_ARGUMENT);
+ analyze("new C1(1, 2, 3);",
+ MessageKind.ADDITIONAL_ARGUMENT);
+}
+
+void testConstructorInvocationArgumentTypes() {
+ compiler.parseScript("""
+ class C1 { C1(x); }
+ class C2 { C2(int x); }
+ """);
+ analyze("new C1(42);");
+ analyze("new C1('string');");
+ analyze("new C2(42);");
+ analyze("new C2('string');",
+ MessageKind.NOT_ASSIGNABLE);
+}
+
void testMethodInvocationArgumentCount() {
compiler.parseScript(CLASS_WITH_METHODS);
final String header = "{ ClassWithMethods c; ";
@@ -199,6 +236,12 @@ void testMethodInvocations() {
analyze("${header}int k = c.intTwoArgumentMethod(i, j); }");
analyze("${header}ClassWithMethods x = c.intTwoArgumentMethod(i, j); }",
MessageKind.NOT_ASSIGNABLE);
+
+ analyze("${header}c.intField(); }",
+ MessageKind.METHOD_NOT_FOUND);
+ analyze("${header}d.intField(); }",
+ MessageKind.METHOD_NOT_FOUND);
+
}
/** Tests analysis of returns (not required by the specification). */
« no previous file with comments | « no previous file | lib/compiler/implementation/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698