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

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

Issue 11314019: Using 'interface' and 'abstract' for methods should produce error (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 602f2e70a7789910efcceaca44447985415df656..2620597fe7544ad9098a65555c35e51702091395 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -3,6 +3,9 @@
// BSD-style license that can be found in the LICENSE file.
package com.google.dart.compiler.type;
+import static com.google.dart.compiler.common.ErrorExpectation.assertErrors;
+import static com.google.dart.compiler.common.ErrorExpectation.errEx;
+
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -36,7 +39,6 @@ import com.google.dart.compiler.ast.DartMethodDefinition;
import com.google.dart.compiler.ast.DartMethodInvocation;
import com.google.dart.compiler.ast.DartNewExpression;
import com.google.dart.compiler.ast.DartNode;
-import com.google.dart.compiler.ast.DartParameter;
import com.google.dart.compiler.ast.DartPropertyAccess;
import com.google.dart.compiler.ast.DartTypeNode;
import com.google.dart.compiler.ast.DartUnaryExpression;
@@ -54,9 +56,6 @@ import com.google.dart.compiler.resolver.NodeElement;
import com.google.dart.compiler.resolver.ResolverErrorCode;
import com.google.dart.compiler.resolver.TypeErrorCode;
-import static com.google.dart.compiler.common.ErrorExpectation.assertErrors;
-import static com.google.dart.compiler.common.ErrorExpectation.errEx;
-
import java.io.Reader;
import java.io.StringReader;
import java.net.URI;
@@ -535,83 +534,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
}
/**
- * From specification 0.05, 11/14/2011.
- * <p>
- * It is a static type warning if the type of the nth required formal parameter of kI is not
- * identical to the type of the nth required formal parameter of kF.
- * <p>
- * It is a static type warning if the types of named optional parameters with the same name differ
- * between kI and kF .
- * <p>
- * http://code.google.com/p/dart/issues/detail?id=521
- */
- public void test_resolveInterfaceConstructor_hasByName_negative_notSameParametersType()
- throws Exception {
- AnalyzeLibraryResult libraryResult =
- analyzeLibrary(
- "Test.dart",
- Joiner.on("\n").join(
- "interface I default F {",
- " I.foo(int a, [int b, int c]);",
- "}",
- "class F implements I {",
- " factory F.foo(num any, [bool b, Object c]) {}",
- "}",
- "class Test {",
- " foo() {",
- " new I.foo(0);",
- " }",
- "}"));
- // No compilation errors.
- assertErrors(libraryResult.getCompilationErrors());
- // Check type warnings.
- {
- List<DartCompilationError> errors = libraryResult.getTypeErrors();
- assertErrors(errors, errEx(TypeErrorCode.DEFAULT_CONSTRUCTOR_TYPES, 2, 3, 29));
- assertEquals(
- "Constructor 'I.foo' in 'I' has parameters types (int,int,int), doesn't match 'F.foo' in 'F' with (num,bool,Object)",
- errors.get(0).getMessage());
- }
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next();
- // "new I.foo()" - resolved, but we produce error.
- {
- DartNewExpression newExpression = findNodeBySource(unit, "new I.foo(0)");
- DartNode constructorNode = newExpression.getElement().getNode();
- assertEquals(true, constructorNode.toSource().contains("F.foo("));
- }
- }
-
- /**
- * There was problem that <code>this.fieldName</code> constructor parameter had no type, so we
- * produced incompatible interface/default class warning.
- */
- public void test_resolveInterfaceConstructor_sameParametersType_thisFieldParameter()
- throws Exception {
- AnalyzeLibraryResult libraryResult =
- analyzeLibrary(
- "Test.dart",
- Joiner.on("\n").join(
- "interface I default F {",
- " I(int a);",
- "}",
- "class F implements I {",
- " int a;",
- " F(this.a) {}",
- "}"));
- // Check that parameter has resolved type.
- {
- DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next();
- DartClass classF = (DartClass) unit.getTopLevelNodes().get(1);
- DartMethodDefinition methodF = (DartMethodDefinition) classF.getMembers().get(1);
- DartParameter parameter = methodF.getFunction().getParameters().get(0);
- assertEquals("int", parameter.getElement().getType().toString());
- }
- // No errors or type warnings.
- assertErrors(libraryResult.getCompilationErrors());
- assertErrors(libraryResult.getTypeErrors());
- }
-
- /**
* In contrast, if A is intended to be concrete, the checker should warn about all unimplemented
* methods, but allow clients to instantiate it freely.
*/
@@ -1596,7 +1518,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
public void test_implementsAndOverrides_noRequiredParameter() throws Exception {
AnalyzeLibraryResult result =
analyzeLibrary(
- "interface I {",
+ "abstract class I {",
" foo(x);",
"}",
"class C implements I {",
@@ -1613,7 +1535,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
public void test_implementsAndOverrides_additionalNamedParameter() throws Exception {
AnalyzeLibraryResult result =
analyzeLibrary(
- "interface I {",
+ "abstract class I {",
" foo([x]);",
"}",
"class C implements I {",
@@ -1625,14 +1547,14 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
public void test_implementsAndOverrides_lessNamedParameter() throws Exception {
AnalyzeLibraryResult result = analyzeLibrary(
"abstract class A {",
- " abstract foo([x, y]);",
+ " foo([x, y]);",
"}",
"abstract class B extends A {",
- " abstract foo([x]);",
+ " foo([x]);",
"}");
assertErrors(
result.getErrors(),
- errEx(ResolverErrorCode.CANNOT_OVERRIDE_METHOD_NAMED_PARAMS, 5, 12, 3));
+ errEx(ResolverErrorCode.CANNOT_OVERRIDE_METHOD_NAMED_PARAMS, 5, 3, 3));
}
/**
@@ -1643,7 +1565,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
AnalyzeLibraryResult result =
analyzeLibrary(
"abstract class A {",
- " abstract foo();",
+ " foo();",
"}",
"class B extends A {",
" foo([x]) {}",
@@ -1661,7 +1583,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
public void test_implementsAndOverrides_extraRequiredParameter() throws Exception {
AnalyzeLibraryResult result =
analyzeLibrary(
- "interface I {",
+ "abstract class I {",
" foo();",
"}",
"class C implements I {",
@@ -1709,7 +1631,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
public void test_implementsAndOverrides_noNamedParameter() throws Exception {
AnalyzeLibraryResult result =
analyzeLibrary(
- "interface I {",
+ "abstract class I {",
" foo([x,y]);",
"}",
"class C implements I {",
@@ -1758,7 +1680,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
public void testImplementsAndOverrides5() throws Exception {
AnalyzeLibraryResult result =
analyzeLibrary(
- "interface I {",
+ "abstract class I {",
" foo([y,x]);",
"}",
"class C implements I {",
@@ -1948,7 +1870,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
AnalyzeLibraryResult result =
analyzeLibrary(
"// filler filler filler filler filler filler filler filler filler filler",
- "interface I<T extends num> { }",
+ "abstract class I<T extends num> { }",
"class A<T extends num> implements I<T> { }",
"class B<T> implements I<T> { }"); // static type error B.T not assignable to num
assertErrors(result.getErrors(), errEx(TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE, 4, 25, 1));
@@ -3140,10 +3062,10 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
public void test_typesPropagation_conditional() throws Exception {
AnalyzeLibraryResult libraryResult = analyzeLibrary(
"// filler filler filler filler filler filler filler filler filler filler",
- "interface I1 {",
+ "abstract class I1 {",
" f1();",
"}",
- "interface I2 {",
+ "abstract class I2 {",
" f2();",
"}",
"class A implements I1, I2 {",
@@ -3719,7 +3641,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
public void test_incompatibleTypesInHierarchy1() throws Exception {
AnalyzeLibraryResult libraryResult = analyzeLibrary(
"// filler filler filler filler filler filler filler filler filler filler",
- "interface Interface<T> {",
+ "abstract class Interface<T> {",
" T m();",
"}",
"abstract class A implements Interface {",
@@ -3734,7 +3656,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
public void test_incompatibleTypesInHierarchy2() throws Exception {
AnalyzeLibraryResult libraryResult = analyzeLibrary(
"// filler filler filler filler filler filler filler filler filler filler",
- "interface Interface<T> {",
+ "abstract class Interface<T> {",
" T m();",
"}",
"abstract class A implements Interface<String> {",
@@ -4388,7 +4310,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
" external A() {}",
" external factory A.named() {}",
" external classMethod() {}",
- " external abstract classMethodAbstract();",
"}",
"");
assertErrors(
@@ -4396,8 +4317,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
errEx(ParserErrorCode.EXTERNAL_METHOD_BODY, 2, 24, 2),
errEx(ParserErrorCode.EXTERNAL_METHOD_BODY, 4, 16, 2),
errEx(ParserErrorCode.EXTERNAL_METHOD_BODY, 5, 30, 2),
- errEx(ParserErrorCode.EXTERNAL_METHOD_BODY, 6, 26, 2),
- errEx(ParserErrorCode.EXTERNAL_ABSTRACT, 7, 12, 8));
+ errEx(ParserErrorCode.EXTERNAL_METHOD_BODY, 6, 26, 2));
}
/**
@@ -5028,19 +4948,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
/**
* <p>
- * http://code.google.com/p/dart/issues/detail?id=5084
- */
- public void test_duplicateSuperInterface_okInInterfaceExtends() throws Exception {
- AnalyzeLibraryResult result = analyzeLibrary(
- "// filler filler filler filler filler filler filler filler filler filler",
- "interface A {}",
- "interface B extends A, A {}",
- "");
- assertErrors(result.getErrors());
- }
-
- /**
- * <p>
* http://code.google.com/p/dart/issues/detail?id=5082
*/
public void test_argumentDefinitionTest_type() throws Exception {

Powered by Google App Engine
This is Rietveld 408576698