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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java

Issue 9403026: Issue 1575. Allow declare new named parameters in method override. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Style tweaks. Created 8 years, 10 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: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
index cc0992d9c1759c1d2a77ad33e32c864ec745fc7a..0daddf6937fc3ea85b1b78ea90b2d7ad1a7b74d2 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -762,4 +762,117 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
assertNotNull(symbol);
assertSame(unit, symbol.getNode().getParent());
}
+
+ /**
+ * No required parameter "x".
+ */
+ public void test_implementsAndOverrides_noRequiredParameter() throws Exception {
+ AnalyzeLibraryResult result =
+ analyzeLibrary(
+ "interface I {",
+ " foo(x);",
+ "}",
+ "class C implements I {",
+ " foo() {}",
+ "}");
+ assertErrors(
+ result.getErrors(),
+ errEx(ResolverErrorCode.CANNOT_OVERRIDE_METHOD_NUM_REQUIRED_PARAMS, 5, 3, 3));
+ }
+
+ /**
+ * It is OK to add more named parameters, if list prefix is same as in "super".
+ */
+ public void test_implementsAndOverrides_additionalNamedParameter() throws Exception {
+ AnalyzeLibraryResult result =
+ analyzeLibrary(
+ "interface I {",
+ " foo([x]);",
+ "}",
+ "class C implements I {",
+ " foo([x,y]) {}",
+ "}");
+ assertErrors(result.getErrors());
+ }
+
+ /**
+ * We override "foo" with method that has named parameter. So, this method is not abstract and
+ * class is not abstract too, so no warning.
+ */
+ public void test_implementsAndOverrides_additionalNamedParameter_notAbstract() throws Exception {
+ AnalyzeLibraryResult result =
+ analyzeLibrary(
+ "class A {",
+ " abstract foo();",
+ "}",
+ "class B extends A {",
+ " foo([x]) {}",
+ "}",
+ "bar() {",
+ " new B();",
+ "}",
+ "");
+ assertErrors(result.getErrors());
+ }
+
+ /**
+ * No required parameter "x". Named parameter "x" is not enough.
+ */
+ public void test_implementsAndOverrides_extraRequiredParameter() throws Exception {
+ AnalyzeLibraryResult result =
+ analyzeLibrary(
+ "interface I {",
+ " foo();",
+ "}",
+ "class C implements I {",
+ " foo(x) {}",
+ "}");
+ assertErrors(
+ result.getErrors(),
+ errEx(ResolverErrorCode.CANNOT_OVERRIDE_METHOD_NUM_REQUIRED_PARAMS, 5, 3, 3));
+ }
+
+ /**
+ * It is a compile-time error if an instance method m1 overrides an instance member m2 and m1 does
+ * not declare all the named parameters declared by m2 in the same order.
+ * <p>
+ * Here: no "y" parameter.
+ */
+ public void test_implementsAndOverrides_noNamedParameter() throws Exception {
+ AnalyzeLibraryResult result =
+ analyzeLibrary(
+ "interface I {",
+ " foo([x,y]);",
+ "}",
+ "class C implements I {",
+ " foo([x]) {}",
+ "}");
+ assertErrors(
+ result.getErrors(),
+ errEx(ResolverErrorCode.CANNOT_OVERRIDE_METHOD_NAMED_PARAMS, 5, 3, 3));
+ }
+
+ /**
+ * It is a compile-time error if an instance method m1 overrides an instance member m2 and m1 does
+ * not declare all the named parameters declared by m2 in the same order.
+ * <p>
+ * Here: wrong order.
+ */
+ public void testImplementsAndOverrides5() throws Exception {
+ AnalyzeLibraryResult result =
+ analyzeLibrary(
+ "interface I {",
+ " foo([y,x]);",
+ "}",
+ "class C implements I {",
+ " foo([x,y]) {}",
+ "}");
+ assertErrors(
+ result.getErrors(),
+ errEx(ResolverErrorCode.CANNOT_OVERRIDE_METHOD_NAMED_PARAMS, 5, 3, 3));
+ }
+
+ private AnalyzeLibraryResult analyzeLibrary(String... lines) throws Exception {
+ return analyzeLibrary(getName(), makeCode(lines));
+ }
}
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698