diff --git a/compiler/java/com/google/dart/compiler/parser/DartParser.java b/compiler/java/com/google/dart/compiler/parser/DartParser.java index bcb85e7d45e..d7e94ff569b 100644 --- a/compiler/java/com/google/dart/compiler/parser/DartParser.java +++ b/compiler/java/com/google/dart/compiler/parser/DartParser.java @@ -332,6 +332,13 @@ public class DartParser extends CompletionHooksParserBase { } else if (peekPseudoKeyword(0, INTERFACE_KEYWORD) && peek(1).equals(Token.IDENTIFIER)) { consume(Token.IDENTIFIER); isParsingInterface = true; + // TODO(scheglov) remove after http://code.google.com/p/dart/issues/detail?id=6318 + if (!Elements.isCoreLibrarySource(source) + && !Elements.isLibrarySource(source, "/isolate/isolate.dart") + && !Elements.isLibrarySource(source, "crypto/crypto.dart") + && !Elements.isDart2JsLibrarySource(source)) { + reportError(position(), ParserErrorCode.DEPRECATED_INTERFACE); + } node = done(parseClass()); } else if (peekPseudoKeyword(0, TYPEDEF_KEYWORD) && (peek(1).equals(Token.IDENTIFIER) || peek(1).equals(Token.VOID) || peek(1).equals(Token.AS))) { @@ -1258,9 +1265,6 @@ public class DartParser extends CompletionHooksParserBase { } } if (optionalPseudoKeyword(ABSTRACT_KEYWORD)) { - if (isParsingInterface) { - reportError(position(), ParserErrorCode.ABSTRACT_MEMBER_IN_INTERFACE); - } if (modifiers.isStatic()) { reportError(position(), ParserErrorCode.STATIC_MEMBERS_CANNOT_BE_ABSTRACT); } @@ -1291,6 +1295,22 @@ public class DartParser extends CompletionHooksParserBase { reportError(position(), ParserErrorCode.DISALLOWED_FACTORY_KEYWORD); } } + + // report "abstract" warning after all other checks to don't hide error with warning + // we ignore problems if there was already reported problem after given position + if (modifiers.isAbstract()) { + // TODO(scheglov) remove after http://code.google.com/p/dart/issues/detail?id=6322 + // TODO(scheglov) remove after http://code.google.com/p/dart/issues/detail?id=6323 + if (!Elements.isCoreLibrarySource(source) + && !Elements.isLibrarySource(source, "html/dartium/html_dartium.dart") + && !Elements.isLibrarySource(source, "/math/math.dart") + && !Elements.isLibrarySource(source, "/io/io_runtime.dart") + && !Elements.isLibrarySource(source, "/crypto/crypto.dart") + && !Elements.isLibrarySource(source, "/utf/utf.dart") + && !Elements.isDart2JsLibrarySource(source)) { + reportError(position(), ParserErrorCode.DEPRECATED_ABSTRACT_METHOD); + } + } if (modifiers.isFactory()) { if (!isParsingClass) { diff --git a/compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java b/compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java index 54cc27d9a01..0e3a53617e6 100644 --- a/compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java +++ b/compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java @@ -33,8 +33,10 @@ public enum ParserErrorCode implements ErrorCode { DEFAULT_POSITIONAL_PARAMETER("Positional parameters cannot have default values"), DEPRECATED_CATCH("This style of catch clause has been deprecated. Please use the 'on' " + "'catch' '(' (',' )? ')' form."), + DEPRECATED_ABSTRACT_METHOD(ErrorSeverity.WARNING, "Modifier 'abstract' is deprecated for methods without body. Remove it."), DEPRECATED_GETTER("The presence of parentheses after the name of the getter " + "has been deprecated and will soon be disallowed. Please remove the parentheses."), + DEPRECATED_INTERFACE("Deprecated declaration of the 'interface', use abstract 'class' instead"), DEPRECATED_USE_OF_FACTORY_KEYWORD("Deprecated use of the 'factory' keyword: use 'default' instead"), DEPRECATED_RAW_STRING("The use of '@' to prefix a raw string has been deprecated; use 'r' instead"), DEPRECATED_RESOURCE_DIRECTIVE("The #resource directive has been deprecated and will soon be disallowed"), @@ -73,9 +75,9 @@ public enum ParserErrorCode implements ErrorCode { EXPECTED_TOKEN("Unexpected token '%s' (expected '%s')"), // TODO(zundel): error message needs JUnit test EXPECTED_VAR_FINAL_OR_TYPE("Expected 'var', 'final' or type"), + EXTERNAL_ABSTRACT("External methods cannot be abstract"), EXTERNAL_ONLY_METHOD("Only a top-level function, a method, a getter, a setter or an non-redirecting constructor can be specified as external"), EXTERNAL_METHOD_BODY("External methods cannot have body"), - EXTERNAL_ABSTRACT("External methods cannot be abstract"), INVALID_SEPARATOR_FOR_NAMED("Use ':' between a named parameter and its value"), INVALID_SEPARATOR_FOR_OPTIONAL("Use '=' between an optional parameter and its value"), // TODO(zundel): this error message is out of date diff --git a/compiler/java/com/google/dart/compiler/resolver/Elements.java b/compiler/java/com/google/dart/compiler/resolver/Elements.java index de005ef732a..55f1401de47 100644 --- a/compiler/java/com/google/dart/compiler/resolver/Elements.java +++ b/compiler/java/com/google/dart/compiler/resolver/Elements.java @@ -727,6 +727,21 @@ static FieldElementImplementation fieldFromNode(DartField node, } return false; } + + /** + * @return true if given {@link Source} represents library with given name. + */ + public static boolean isDart2JsLibrarySource(Source source) { + if (source instanceof DartSource) { + DartSource dartSource = (DartSource) source; + LibrarySource library = dartSource.getLibrary(); + if (library != null) { + String libraryName = library.getName(); + return libraryName.contains("lib/compiler/implementation/"); + } + } + return false; + } /** * @return true if given {@link Source} represents code library declaration or diff --git a/compiler/java/com/google/dart/compiler/resolver/Resolver.java b/compiler/java/com/google/dart/compiler/resolver/Resolver.java index 2c2f42b44c0..9edadea0aac 100644 --- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java +++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java @@ -84,7 +84,6 @@ import com.google.dart.compiler.type.Type; import com.google.dart.compiler.type.TypeKind; import com.google.dart.compiler.type.TypeVariable; import com.google.dart.compiler.type.Types; -import com.google.dart.compiler.util.apache.StringUtils; import java.util.EnumSet; import java.util.Iterator; @@ -379,14 +378,6 @@ public class Resolver { // Make sure the default class matches the interface type parameters checkInterfaceTypeParamsToDefault(classElement, defaultClass); - - // Check that interface constructors have corresponding methods in default class. - checkInterfaceConstructors(classElement); - } else if (classElement.isInterface() && classElement.getConstructors() != null) { - for (ConstructorElement interfaceConstructor : classElement.getConstructors()) { - onError(interfaceConstructor.getNameLocation(), - ResolverErrorCode.ILLEGAL_CONSTRUCTOR_NO_DEFAULT_IN_INTERFACE); - } } if (!classElement.isInterface() && Elements.needsImplicitDefaultConstructor(classElement)) { @@ -549,73 +540,6 @@ public class Resolver { } } - /** - * Checks that interface constructors have corresponding methods in default class. - */ - private void checkInterfaceConstructors(ClassElement interfaceElement) { - String interfaceClassName = interfaceElement.getName(); - String defaultClassName = interfaceElement.getDefaultClass().getElement().getName(); - - for (ConstructorElement interfaceConstructor : interfaceElement.getConstructors()) { - ConstructorElement defaultConstructor = - resolveInterfaceConstructorInDefaultClass( - interfaceConstructor, - interfaceConstructor); - if (defaultConstructor != null) { - // Remember for TypeAnalyzer. - interfaceConstructor.setDefaultConstructor(defaultConstructor); - // Validate number of required parameters. - { - int numReqInterface = Elements.getNumberOfRequiredParameters(interfaceConstructor); - int numReqDefault = Elements.getNumberOfRequiredParameters(defaultConstructor); - if (numReqInterface != numReqDefault) { - onError( - interfaceConstructor, - ResolverErrorCode.DEFAULT_CONSTRUCTOR_NUMBER_OF_REQUIRED_PARAMETERS, - Elements.getRawMethodName(interfaceConstructor), - interfaceClassName, - numReqInterface, - Elements.getRawMethodName(defaultConstructor), - defaultClassName, - numReqDefault); - } - } - // Validate number of required parameters. - { - int numInterface = Elements.getNumberOfOptionalPositionalParameters(interfaceConstructor); - int numDefault = Elements.getNumberOfOptionalPositionalParameters(defaultConstructor); - if (numInterface != numDefault) { - onError( - interfaceConstructor, - ResolverErrorCode.DEFAULT_CONSTRUCTOR_OPTIONAL_POSITIONAL_PARAMETERS, - Elements.getRawMethodName(interfaceConstructor), - interfaceClassName, - numInterface, - Elements.getRawMethodName(defaultConstructor), - defaultClassName, - numDefault); - } - } - // Validate names of named parameters. - { - List interfaceNames = Elements.getNamedParameters(interfaceConstructor); - List defaultNames = Elements.getNamedParameters(defaultConstructor); - if (!interfaceNames.equals(defaultNames)) { - onError( - interfaceConstructor, - ResolverErrorCode.DEFAULT_CONSTRUCTOR_NAMED_PARAMETERS, - Elements.getRawMethodName(interfaceConstructor), - interfaceClassName, - interfaceNames, - Elements.getRawMethodName(defaultConstructor), - defaultClassName, - defaultNames); - } - } - } - } - } - /** * Returns true if the {@link ClassElement} has an implicit or a declared * default constructor. @@ -1717,9 +1641,6 @@ public class Resolver { // Will check that element is not null. ConstructorElement constructor = checkIsConstructor(x, element); - // try to lookup the constructor in the default class. - constructor = resolveInterfaceConstructorInDefaultClass(x.getConstructor(), constructor); - // Check constructor. if (constructor != null) { boolean constConstructor = constructor.getModifiers().isConstant(); @@ -1742,87 +1663,6 @@ public class Resolver { return recordElement(x, constructor); } - /** - * If given {@link ConstructorElement} is declared in interface, try to resolve it in - * corresponding default class. - * - * @return the resolved {@link ConstructorElement}, or same as given. - */ - private ConstructorElement resolveInterfaceConstructorInDefaultClass(HasSourceInfo errorTarget, - ConstructorElement constructor) { - // If no default class, use existing constructor. - if (constructor == null || constructor.getConstructorType().getDefaultClass() == null) { - return constructor; - } - // Prepare elements and names for classes. - ClassElement originalClass = constructor.getConstructorType(); - ClassElement defaultClass = originalClass.getDefaultClass().getElement(); - String originalClassName = originalClass.getName(); - String defaultClassName = defaultClass.getName(); - // Prepare "qualifier.name" for original constructor. - String rawOriginalMethodName = Elements.getRawMethodName(constructor); - int originalDotIndex = rawOriginalMethodName.indexOf('.'); - String originalQualifier = StringUtils.substringBefore(rawOriginalMethodName, "."); - String originalName = StringUtils.substringAfter(rawOriginalMethodName, "."); - // Separate checks for cases when factory implements interface and not. - boolean factoryImplementsInterface = Elements.implementsType(defaultClass, originalClass); - if (factoryImplementsInterface) { - for (ConstructorElement defaultConstructor : defaultClass.getConstructors()) { - String rawDefaultMethodName = Elements.getRawMethodName(defaultConstructor); - // kI == nI and kF == nF - if (rawOriginalMethodName.equals(originalClassName) - && rawDefaultMethodName.equals(defaultClassName)) { - return defaultConstructor; - } - // kI == nI.name and kF == nF.name - if (originalDotIndex != -1) { - int defaultDotIndex = rawDefaultMethodName.indexOf('.'); - if (defaultDotIndex != -1) { - String defaultQualifier = StringUtils.substringBefore(rawDefaultMethodName, "."); - String defaultName = StringUtils.substringAfter(rawDefaultMethodName, "."); - if (defaultQualifier.equals(defaultClassName) - && originalQualifier.equals(originalClassName) - && defaultName.equals(originalName)) { - return defaultConstructor; - } - } - } - } - } else { - for (ConstructorElement defaultConstructor : defaultClass.getConstructors()) { - String rawDefaultMethodName = Elements.getRawMethodName(defaultConstructor); - if (rawDefaultMethodName.equals(rawOriginalMethodName)) { - return defaultConstructor; - } - } - } - // If constructor not found, try implicit default constructor of the default class. - if (Elements.isDefaultConstructor(constructor) - && (Elements.isSyntheticConstructor(constructor) || factoryImplementsInterface) - && Elements.needsImplicitDefaultConstructor(defaultClass)) { - return new SyntheticDefaultConstructorElement(null, defaultClass, typeProvider); - } - // Factory constructor not resolved, report error with specific message for each case. - { - String expectedFactoryConstructorName; - if (factoryImplementsInterface) { - if (originalDotIndex == -1) { - expectedFactoryConstructorName = defaultClassName; - } else { - expectedFactoryConstructorName = defaultClassName + "." + originalName; - } - } else { - expectedFactoryConstructorName = rawOriginalMethodName; - } - onError( - errorTarget, - ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, - expectedFactoryConstructorName, - defaultClassName); - return null; - } - } - @Override public Element visitGotoStatement(DartGotoStatement x) { // Don't bother unless there's a target. diff --git a/compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java b/compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java index 1f1126ce63e..b081100d566 100644 --- a/compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java +++ b/compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java @@ -125,8 +125,6 @@ public enum ResolverErrorCode implements ErrorCode { ILLEGAL_ACCESS_TO_PRIVATE("'%s' is private and not defined in this library"), // TODO(zundel): error message needs JUnit test - how to test #imports in junit? ILLEGAL_ACCESS_TO_PRIVATE_MEMBER("\"%s\" refers to \"%s\" which is in a different library"), - ILLEGAL_CONSTRUCTOR_NO_DEFAULT_IN_INTERFACE( - "Illegal constructor declaration. No default clause in interface"), ILLEGAL_FIELD_ACCESS_FROM_STATIC("Illegal access of instance field %s from static scope"), ILLEGAL_METHOD_ACCESS_FROM_STATIC("Illegal access of instance method %s from static scope"), INIT_FIELD_ONLY_IMMEDIATELY_SURROUNDING_CLASS( diff --git a/compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilation2Test.java b/compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilation2Test.java index 9b1c9455a48..ac993803034 100644 --- a/compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilation2Test.java +++ b/compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilation2Test.java @@ -3,6 +3,11 @@ // BSD-style license that can be found in the LICENSE file. package com.google.dart.compiler.end2end.inc; +import static com.google.dart.compiler.DartCompiler.EXTENSION_DEPS; +import static com.google.dart.compiler.DartCompiler.EXTENSION_TIMESTAMP; +import static com.google.dart.compiler.common.ErrorExpectation.assertErrors; +import static com.google.dart.compiler.common.ErrorExpectation.errEx; + import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -23,11 +28,7 @@ import com.google.dart.compiler.ast.LibraryUnit; import com.google.dart.compiler.common.ErrorExpectation; import com.google.dart.compiler.resolver.ResolverErrorCode; import com.google.dart.compiler.resolver.TypeErrorCode; - -import static com.google.dart.compiler.DartCompiler.EXTENSION_DEPS; -import static com.google.dart.compiler.DartCompiler.EXTENSION_TIMESTAMP; -import static com.google.dart.compiler.common.ErrorExpectation.assertErrors; -import static com.google.dart.compiler.common.ErrorExpectation.errEx; +import com.google.dart.compiler.util.apache.StringUtils; import junit.framework.AssertionFailedError; @@ -936,40 +937,6 @@ public class IncrementalCompilation2Test extends CompilerTestCase { errEx(ResolverErrorCode.CANNOT_ACCESS_METHOD, 6, 5, 7), errEx(ResolverErrorCode.CANNOT_ACCESS_METHOD, 9, 11, 7)); } - - /** - * When we resolve factory constructors, we should check if "lib" is library prefix, it is not - * always have to be name of type. - *

- * http://code.google.com/p/dart/issues/detail?id=2478 - */ - public void test_factoryClass_fromPrefixImportedLibrary() throws Exception { - appSource.setContent( - "A.dart", - makeCode( - "// filler filler filler filler filler filler filler filler filler filler filler", - "library A;", - "import '" + APP + "';", - "interface I default A {", - " I();", - " I.named();", - "}", - "")); - appSource.setContent( - APP, - makeCode( - "// filler filler filler filler filler filler filler filler filler filler filler", - "library application;", - "import 'A.dart' as lib;", - "class A {", - " factory lib.I() {}", - " factory lib.I.named() {}", - "}", - "")); - // do compile, no errors expected - compile(); - assertErrors(errors); - } /** *

diff --git a/compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilationTest.java b/compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilationTest.java index 9e366105d1e..ea7e9e172da 100644 --- a/compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilationTest.java +++ b/compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilationTest.java @@ -17,6 +17,7 @@ import com.google.dart.compiler.LibrarySource; import com.google.dart.compiler.MockArtifactProvider; import com.google.dart.compiler.MockBundleLibrarySource; import com.google.dart.compiler.Source; +import com.google.dart.compiler.util.apache.StringUtils; import junit.framework.AssertionFailedError; @@ -104,6 +105,7 @@ public class IncrementalCompilationTest extends CompilerTestCase { public void testFullCompile() { compile(); + System.out.println(StringUtils.join(errors, "\n")); // Assert that all artifacts are written. didWrite("someimpl.dart", EXTENSION_TIMESTAMP); diff --git a/compiler/javatests/com/google/dart/compiler/end2end/inc/some.dart b/compiler/javatests/com/google/dart/compiler/end2end/inc/some.dart index 8624331e4bd..fc5b2cbd543 100644 --- a/compiler/javatests/com/google/dart/compiler/end2end/inc/some.dart +++ b/compiler/javatests/com/google/dart/compiler/end2end/inc/some.dart @@ -2,12 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface SomeClass default SomeClassImpl { - SomeClass(arg); +abstract class SomeClass { + factory SomeClass(arg) = SomeClassImpl; get message; } -interface SomeInterface2 { +abstract class SomeInterface2 { } // myother7.dart/Baz depends on SomeClass2 which depends on SomeInterface2 diff --git a/compiler/javatests/com/google/dart/compiler/end2end/inc/some.intfchange.dart b/compiler/javatests/com/google/dart/compiler/end2end/inc/some.intfchange.dart index b3d26c33cbc..33e54aba09e 100644 --- a/compiler/javatests/com/google/dart/compiler/end2end/inc/some.intfchange.dart +++ b/compiler/javatests/com/google/dart/compiler/end2end/inc/some.intfchange.dart @@ -2,12 +2,12 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface SomeClass default SomeClassImpl { - SomeClass(arg); +abstract class SomeClass { + factory SomeClass(arg) = SomeClassImpl; String get message; // Added return type } -interface SomeInterface2 { +abstract class SomeInterface2 { } // myother7.dart/Baz depends on SomeClass2 which depends on SomeInterface2 diff --git a/compiler/javatests/com/google/dart/compiler/end2end/inc/some.newmethod.dart b/compiler/javatests/com/google/dart/compiler/end2end/inc/some.newmethod.dart index 92d49246212..bf27f3d96c2 100644 --- a/compiler/javatests/com/google/dart/compiler/end2end/inc/some.newmethod.dart +++ b/compiler/javatests/com/google/dart/compiler/end2end/inc/some.newmethod.dart @@ -2,13 +2,13 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface SomeClass default SomeClassImpl { - SomeClass(arg); - String get message; +abstract class SomeClass { + factory SomeClass(arg) = SomeClassImpl; + get message; newMethod(); } -interface SomeInterface2 { +abstract class SomeInterface2 { } // myother7.dart/Baz depends on SomeClass2 which depends on SomeInterface2 diff --git a/compiler/javatests/com/google/dart/compiler/parser/ClassesInterfaces.dart b/compiler/javatests/com/google/dart/compiler/parser/ClassesInterfaces.dart index 8001649941c..9535c88072b 100644 --- a/compiler/javatests/com/google/dart/compiler/parser/ClassesInterfaces.dart +++ b/compiler/javatests/com/google/dart/compiler/parser/ClassesInterfaces.dart @@ -111,16 +111,16 @@ class Baz extends Kuk implements A, B, C { Baz(x, y, z) : super(x, y, z) {} } -interface Foo extends D, E { +abstract class Foo implements D, E { bar(); } // Test bounds on type parameters -interface Bar extends Foo { +abstract class Bar implements Foo { } -interface Bar extends Foo { +abstract class Bar implements Foo { } -interface Bar extends Foo { +abstract class Bar implements Foo { } diff --git a/compiler/javatests/com/google/dart/compiler/parser/ErrorMessageLocationTest.java b/compiler/javatests/com/google/dart/compiler/parser/ErrorMessageLocationTest.java index 78e402b37ef..cb1376aa93a 100644 --- a/compiler/javatests/com/google/dart/compiler/parser/ErrorMessageLocationTest.java +++ b/compiler/javatests/com/google/dart/compiler/parser/ErrorMessageLocationTest.java @@ -20,7 +20,7 @@ public class ErrorMessageLocationTest extends TestCase { public void testUnexpectedTokenErrorMessage() { String sourceCode = "// Empty comment\n" + - "interface foo while Bar {\n" + + "class foo while Bar {\n" + "}"; DartParserRunner runner = DartParserRunner.parse(getName(), sourceCode); @@ -30,7 +30,7 @@ public class ErrorMessageLocationTest extends TestCase { DartCompilationError actualError = actualErrors.get(0); String errorTokenString = "while"; - assertEquals(15, actualError.getColumnNumber()); + assertEquals(11, actualError.getColumnNumber()); assertEquals(errorTokenString.length(), actualError.getLength()); assertEquals(2, actualError.getLineNumber()); assertEquals(sourceCode.indexOf(errorTokenString), actualError.getStartPosition()); diff --git a/compiler/javatests/com/google/dart/compiler/parser/MethodSignatures.dart b/compiler/javatests/com/google/dart/compiler/parser/MethodSignatures.dart index bceecd6c3ff..6a2b414cf92 100644 --- a/compiler/javatests/com/google/dart/compiler/parser/MethodSignatures.dart +++ b/compiler/javatests/com/google/dart/compiler/parser/MethodSignatures.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface MethodSignatureSyntax { +abstract class MethodSignatureSyntax { a(); b(x); c(int x); diff --git a/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java b/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java index fb2ed408b47..65a57e17726 100644 --- a/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java +++ b/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java @@ -25,6 +25,15 @@ public class NegativeParserTest extends CompilerTestCase { parseExpectErrors("get foo() {}", errEx(ParserErrorCode.DEPRECATED_GETTER, 1, 5, 3)); } + public void test_deprecatedAbstract() { + parseExpectWarnings(makeCode( + "// filler filler filler filler filler filler filler filler filler filler", + "abstract class A {", + " abstract m();", + "}", + ""), errEx(ParserErrorCode.DEPRECATED_ABSTRACT_METHOD, 3, 3, 8)); + } + public void testFieldInitializerInRedirectionConstructor1() { parseExpectErrors( "class A { A(x) { } A.foo() : this(5), y = 5; var y; }", @@ -368,6 +377,7 @@ public class NegativeParserTest extends CompilerTestCase { public void testDeprecatedFactoryInInterface() { parseExpectWarnings( "interface foo factory bar {}", + errEx(ParserErrorCode.DEPRECATED_INTERFACE, 1, 1, 9), errEx(ParserErrorCode.DEPRECATED_USE_OF_FACTORY_KEYWORD, 1, 15, 7)); } @@ -397,8 +407,18 @@ public class NegativeParserTest extends CompilerTestCase { "// filler filler filler filler filler filler filler filler filler filler", "abstract interface A {", "}"), + errEx(ParserErrorCode.DEPRECATED_INTERFACE, 2, 10, 9), errEx(ParserErrorCode.ABSTRACT_TOP_LEVEL_ELEMENT, 2, 1, 8)); } + + public void test_deprecatedInterface() { + parseExpectErrors( + Joiner.on("\n").join( + "// filler filler filler filler filler filler filler filler filler filler", + "interface A {", + "}"), + errEx(ParserErrorCode.DEPRECATED_INTERFACE, 2, 1, 9)); + } public void test_abstractTopLevel_typedef() { parseExpectErrors( @@ -412,17 +432,6 @@ public class NegativeParserTest extends CompilerTestCase { errEx(ParserErrorCode.ABSTRACT_TOP_LEVEL_ELEMENT, 1, 1, 8)); } - public void test_abstractMethodWithBody() { - parseExpectErrors( - Joiner.on("\n").join( - "// filler filler filler filler filler filler filler filler filler filler", - "class A {", - " abstract foo() {", - " }", - "}"), - errEx(ParserErrorCode.ABSTRACT_METHOD_WITH_BODY, 3, 12, 3)); - } - public void test_incompleteExpressionInInterpolation() { parseExpectErrors( "var s = 'fib(3) = ${fib(3}';", @@ -437,6 +446,7 @@ public class NegativeParserTest extends CompilerTestCase { " foo() {", " }", "}"), + errEx(ParserErrorCode.DEPRECATED_INTERFACE, 2, 1, 9), errEx(ParserErrorCode.INTERFACE_METHOD_WITH_BODY, 3, 3, 3)); } @@ -766,6 +776,7 @@ public class NegativeParserTest extends CompilerTestCase { "interface A native 'N' {", "}", ""), + errEx(ParserErrorCode.DEPRECATED_INTERFACE, 2, 1, 9), errEx(ParserErrorCode.NATIVE_ONLY_CLASS, 2, 13, 6)); } diff --git a/compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java b/compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java index e6688bb2285..7bf53403aaa 100644 --- a/compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java +++ b/compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java @@ -1025,11 +1025,10 @@ public class SyntaxTest extends AbstractParserTest { parseUnit("phony_test_missing_factory_body.dart", Joiner.on("\n").join( "class A {", - " abstract factory A.c();", // error - no body + " factory A.c();", // error - no body " A() {}", "}"), - ParserErrorCode.FACTORY_CANNOT_BE_ABSTRACT, 2, 12, - ParserErrorCode.EXPECTED_FUNCTION_STATEMENT_BODY, 2, 25); + ParserErrorCode.EXPECTED_FUNCTION_STATEMENT_BODY, 2, 16); } public void test_factoryAbstractStatic() throws Exception { @@ -1037,25 +1036,10 @@ public class SyntaxTest extends AbstractParserTest { Joiner.on("\n").join( "class A {", " A() {}", - " abstract factory A.named1() { return new A();}", + " factory A.named1() { return new A();}", " static factory A.named2() { return new A();}", - " static abstract factory A.named3() { return new A();}", "}"), - ParserErrorCode.FACTORY_CANNOT_BE_ABSTRACT, 3, 12, - ParserErrorCode.FACTORY_CANNOT_BE_STATIC, 4, 10, - ParserErrorCode.STATIC_MEMBERS_CANNOT_BE_ABSTRACT, 5, 10, - ParserErrorCode.FACTORY_CANNOT_BE_STATIC, 5, 19); - } - - public void test_staticAbstractMember() throws Exception { - parseUnit("phony_test_static_abstract_member.dart", - Joiner.on("\n").join( - "class A {", - " static abstract var foo;", - " static abstract bar();", - "}"), - ParserErrorCode.STATIC_MEMBERS_CANNOT_BE_ABSTRACT, 2, 10, - ParserErrorCode.STATIC_MEMBERS_CANNOT_BE_ABSTRACT, 3, 10); + ParserErrorCode.FACTORY_CANNOT_BE_STATIC, 4, 10); } public void test_factoryInInterface() throws Exception { @@ -1064,21 +1048,11 @@ public class SyntaxTest extends AbstractParserTest { "interface A {", " factory A();", "}"), + ParserErrorCode.DEPRECATED_INTERFACE, 1, 1, ParserErrorCode.FACTORY_MEMBER_IN_INTERFACE, 2, 3, ParserErrorCode.EXPECTED_FUNCTION_STATEMENT_BODY, 2, 14); } - public void test_AbstractVar() throws Exception { - parseUnit("phony_test_abstract_var.dart", - Joiner.on("\n").join( - "class A {", - " abstract var a;", - " abstract final b;", - "}"), - ParserErrorCode.DISALLOWED_ABSTRACT_KEYWORD, 2, 3, - ParserErrorCode.DISALLOWED_ABSTRACT_KEYWORD, 3, 3); - } - public void test_localVariable_const() { DartUnit unit = parseUnit("constVar.dart", makeCode( "main() {", @@ -1401,11 +1375,10 @@ public class SyntaxTest extends AbstractParserTest { parseUnit("phony_test_abstract_in_interface.dart", Joiner.on("\n").join( "interface A {", - " abstract var foo;", - " abstract bar();", + " var foo;", + " bar();", "}"), - ParserErrorCode.ABSTRACT_MEMBER_IN_INTERFACE, 2, 3, - ParserErrorCode.ABSTRACT_MEMBER_IN_INTERFACE, 3, 3); + ParserErrorCode.DEPRECATED_INTERFACE, 1, 1); } public void test_voidParameterField() throws Exception { @@ -1458,6 +1431,7 @@ public class SyntaxTest extends AbstractParserTest { " static foo();", " static var bar;", "}"), + ParserErrorCode.DEPRECATED_INTERFACE, 1, 1, ParserErrorCode.NON_FINAL_STATIC_MEMBER_IN_INTERFACE, 2, 3, ParserErrorCode.NON_FINAL_STATIC_MEMBER_IN_INTERFACE, 3, 3); } @@ -1483,13 +1457,6 @@ public class SyntaxTest extends AbstractParserTest { ParserErrorCode.EXPECTED_TOKEN, 2, 15); } - public void test_abstractMethod_withModifier() { - parseUnit("test.dart", Joiner.on("\n").join( - "class C {", - " abstract m(a, b, c);", - "}")); - } - public void test_abstractMethod_withoutModifier() { parseUnit("test.dart", Joiner.on("\n").join( "class C {", diff --git a/compiler/javatests/com/google/dart/compiler/parser/TryCatch.dart b/compiler/javatests/com/google/dart/compiler/parser/TryCatch.dart index ea95022f82a..47087330ab3 100644 --- a/compiler/javatests/com/google/dart/compiler/parser/TryCatch.dart +++ b/compiler/javatests/com/google/dart/compiler/parser/TryCatch.dart @@ -2,11 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface TestException1 { +abstract class TestException1 { int foo(); } -interface TestException2 { +abstract class TestException2 { int bar(); } diff --git a/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java b/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java index 3a23dab04c7..ae86c276659 100644 --- a/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java +++ b/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java @@ -880,7 +880,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { resolveAndTestCtConstExpectErrors( Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class A {", " const int value1 = (1 << 5) - 1;", " const int value2 = value1 & 0xFFFF;", @@ -901,7 +901,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { resolveAndTestCtConstExpectErrors( Joiner.on("\n").join( "class Object {}", - "interface double {}", + "class double {}", "class A {", " const double value1 = (1.0 * 5.0) - 1.0;", " const double value2 = value1 + 99.0;", @@ -922,7 +922,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { resolveAndTestCtConstExpectErrors( Joiner.on("\n").join( "class Object {}", - "interface double {}", + "class double {}", "class A {", " const double value1 = (1 * 5) - 1.0;", " const double value2 = value1 + 99.0;", @@ -943,7 +943,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { resolveAndTestCtConstExpectErrors( Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class A {", " const int value1 = ('Invalid') - 1;", " const int value2 = value1 & 0xFFFF;", @@ -958,7 +958,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { resolveAndTestCtConstExpectErrors( Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class A {", " const int value3 = ('Invalid') + 1;", " const int value4 = value3 & 0xFFFF;", @@ -970,7 +970,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { resolveAndTestCtConstExpectErrors( Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class A {", " const int value5 = ('Invalid') * 1;", " const int value6 = value5 & 0xFFFF;", @@ -982,7 +982,7 @@ public class CompileTimeConstantTest extends ResolverTestCase { resolveAndTestCtConstExpectErrors( Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class A {", " const int value7 = ('Invalid') / 1;", " const int value8 = value7 & 0xFFFF;", diff --git a/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java b/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java index fced3490009..28d4dc586a1 100644 --- a/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java +++ b/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java @@ -245,20 +245,6 @@ public class NegativeResolverTest extends CompilerTestCase { checkNumErrors("StaticInstanceCallNegativeTest.dart", 1); } - /** - * Section 7.8: It is a compile-time error if the extends clause of a class C includes a type - * expression that does not denote a class available in the lexical scope of C. - */ - public void test_classExtendsInterface() { - checkSourceErrors( - makeCode( - "// filler filler filler filler filler filler filler filler filler filler", - "interface I {}", - "class A extends I {", - "}"), - errEx(ResolverErrorCode.NOT_A_CLASS, 3, 17, 1)); - } - /** * Class can implement class, this causes implementation of an implicit interface. */ @@ -270,17 +256,6 @@ public class NegativeResolverTest extends CompilerTestCase { "}")); } - /** - * Interface can extend class, this causes implementation of an implicit interface. - */ - public void test_interfaceExtendsClass() { - checkSourceErrors(makeCode( - "// filler filler filler filler filler filler filler filler filler filler", - "class A {}", - "interface B extends A {", - "}")); - } - public void tesClassImplementsUnknownInterfaceNegativeTest() { checkNumErrors("ClassImplementsUnknownInterfaceNegativeTest.dart", 1); } @@ -648,7 +623,7 @@ public class NegativeResolverTest extends CompilerTestCase { public void test_nameShadow_field_interfaceMethodParameter() { checkSourceErrors(makeCode( "// filler filler filler filler filler filler filler filler filler filler", - "interface A {", + "abstract class A {", " var a;", " foo(a);", "}")); @@ -864,10 +839,6 @@ public class NegativeResolverTest extends CompilerTestCase { errEx(ResolverErrorCode.CONST_CONSTRUCTOR_MUST_CALL_CONST_SUPER, 3, 9, 1)); } - public void testRawTypesNegativeTest() { - checkNumErrors("RawTypesNegativeTest.dart", 6); - } - public void testConstConstructorNonFinalFieldsNegativeTest() { checkSourceErrors( makeCode( @@ -881,7 +852,7 @@ public class NegativeResolverTest extends CompilerTestCase { " final bar;", " var baz;", "}", - "interface C {", + "abstract class C {", " var x;", "}"), errEx(ResolverErrorCode.CONST_CLASS_WITH_NONFINAL_FIELDS, 3, 7, 1), @@ -1048,17 +1019,6 @@ public class NegativeResolverTest extends CompilerTestCase { errEx(ResolverErrorCode.THIS_IN_INITIALIZER_AS_EXPRESSION, 5, 25, 4)); } - public void testInterfaceWithConcreteConstructorAndDefaultNonImlplementing() throws Exception { - checkSourceErrors( - makeCode( - "// filler filler filler filler filler filler filler filler filler filler", - "class A {}", - "interface I default A {", - " I();", - "}"), - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, 4, 3, 4)); - } - public void test_resolvedTypeVariableBounds_inFunctionTypeAlias() throws Exception { DartUnit unit = parseUnit( diff --git a/compiler/javatests/com/google/dart/compiler/resolver/RawTypesNegativeTest.dart b/compiler/javatests/com/google/dart/compiler/resolver/RawTypesNegativeTest.dart deleted file mode 100644 index aaa3bb39c81..00000000000 --- a/compiler/javatests/com/google/dart/compiler/resolver/RawTypesNegativeTest.dart +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -interface Super {} - -interface Sub extends Super default SubImplementation { - Sub(); -} - -class SubImplementation implements Sub { - SubImplementation() {} -} - -class A { - main() { - Sub s = new Sub(); - Sub s2 = new Sub(); - Sub s3; - A s4; - } -} diff --git a/compiler/javatests/com/google/dart/compiler/resolver/ResolverCompilerTest.java b/compiler/javatests/com/google/dart/compiler/resolver/ResolverCompilerTest.java index 7261bcae6a2..0c2cf53c0c6 100644 --- a/compiler/javatests/com/google/dart/compiler/resolver/ResolverCompilerTest.java +++ b/compiler/javatests/com/google/dart/compiler/resolver/ResolverCompilerTest.java @@ -7,7 +7,6 @@ import com.google.common.base.Joiner; import com.google.common.collect.Lists; import com.google.common.io.CharStreams; import com.google.dart.compiler.CompilerTestCase; -import com.google.dart.compiler.DartCompilationError; import com.google.dart.compiler.Source; import com.google.dart.compiler.ast.ASTVisitor; import com.google.dart.compiler.ast.DartClass; @@ -90,13 +89,12 @@ public class ResolverCompilerTest extends CompilerTestCase { "Test.dart", Joiner.on("\n").join( "class A {}", - "interface B default C {}", + "abstract class B {}", "class C extends A implements B {}", "class D extends C {}", "class E implements C {}", "class F {}", - "class G extends F> {}", - "interface H default C {}")); + "class G extends F> {}")); assertErrors(libraryResult.getCompilationErrors()); DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); List nodes = unit.getTopLevelNodes(); @@ -114,8 +112,6 @@ public class ResolverCompilerTest extends CompilerTestCase { assertEquals("F", F.getClassName()); DartClass G = (DartClass) nodes.get(6); assertEquals("G", G.getClassName()); - DartClass H = (DartClass) nodes.get(7); - assertEquals("H", H.getClassName()); // class A assertNotNull(A.getName().getElement()); @@ -131,8 +127,6 @@ public class ResolverCompilerTest extends CompilerTestCase { assertNotNull(T.getName().getElement()); assertTrue(T.getName().getElement() instanceof TypeVariableElement); assertEquals("T", T.getName().getName()); - assertNotNull(B.getDefaultClass().getExpression().getElement()); - assertSame(C.getElement(), B.getDefaultClass().getExpression().getElement()); // class C extends A implements B {} assertNotNull(C.getName().getElement()); @@ -193,24 +187,6 @@ public class ResolverCompilerTest extends CompilerTestCase { assertEquals( "int", typeArg.getTypeArguments().get(0).getIdentifier().getElement().getOriginalName()); - - // class H extends C {}", - assertNotNull(H.getName().getElement()); - assertSame(H.getElement(), H.getName().getElement()); - assertEquals(1, H.getTypeParameters().size()); - T = H.getTypeParameters().get(0); - assertNotNull(T); - assertNotNull(T.getName().getElement()); - assertTrue(T.getName().getElement() instanceof TypeVariableElement); - assertNotNull(H.getDefaultClass().getExpression().getElement()); - assertSame(C.getElement(), H.getDefaultClass().getExpression().getElement()); - // This type parameter T resolves to the Type variable on the default class, so it - // isn't the same type variable instance specified in this interface declaration, - // though it must have the same name. - DartTypeParameter defaultT = H.getDefaultClass().getTypeParameters().get(0); - assertNotNull(defaultT.getName().getElement()); - assertTrue(defaultT.getName().getElement() instanceof TypeVariableElement); - assertEquals(T.getName().getElement().getName(), defaultT.getName().getElement().getName()); } /** @@ -287,544 +263,6 @@ public class ResolverCompilerTest extends CompilerTestCase { errEx(ResolverErrorCode.SUPER_METHOD_INVOCATION_IN_CONSTRUCTOR_INITIALIZER, 7, 13, 11)); } - /** - * We should be able to resolve implicit default constructor. - */ - public void test_resolveInterfaceConstructor_implicitDefault_noInterface_noFactory() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - "}", - "class F implements I {", - "}", - "class Test {", - " foo() {", - " new I();", - " }", - "}")); - assertErrors(libraryResult.getCompilationErrors()); - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - DartNewExpression newExpression = findNodeBySource(unit, "new I()"); - ConstructorElement constructorElement = newExpression.getElement(); - assertNotNull(constructorElement); - assertEquals("", getElementSource(constructorElement)); - } - - /** - * We should be able to resolve implicit default constructor. - */ - public void test_resolveInterfaceConstructor_implicitDefault_hasInterface_noFactory() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - "}", - "class F implements I {", - "}", - "class Test {", - " foo() {", - " new I();", - " }", - "}")); - assertErrors(libraryResult.getCompilationErrors()); - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - DartNewExpression newExpression = findNodeBySource(unit, "new I()"); - ConstructorElement constructorElement = newExpression.getElement(); - assertNotNull(constructorElement); - assertEquals("", getElementSource(constructorElement)); - } - - /** - * We should be able to resolve implicit default constructor. - */ - public void test_resolveInterfaceConstructor_implicitDefault_noInterface_hasFactory() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - "}", - "class F implements I {", - " F();", - "}", - "class Test {", - " foo() {", - " new I();", - " }", - "}")); - assertErrors(libraryResult.getCompilationErrors()); - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - DartNewExpression newExpression = findNodeBySource(unit, "new I()"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("F()")); - } - - /** - * If "const I()" is used, then constructor should be "const". - */ - public void test_resolveInterfaceConstructor_const() throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - " I(int x);", - "}", - "class F implements I {", - " F(int y) {}", - "}", - "class Test {", - " foo() {", - " const I(0);", - " }", - "}")); - assertErrors( - libraryResult.getCompilationErrors(), - errEx(ResolverErrorCode.CONST_AND_NONCONST_CONSTRUCTOR, 9, 5, 10)); - } - - /** - * From specification 0.05, 11/14/2011. - *

- * A constructor kI of I corresponds to a constructor kF of its factory class F if either - *

- *

- * http://code.google.com/p/dart/issues/detail?id=521 - */ - public void test_resolveInterfaceConstructor_whenFactoryImplementsInterface_nameIsIdentifier() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - " I(int x);", - "}", - "class F implements I {", - " F(int y) {}", - " factory I(int y) {}", - "}", - "class Test {", - " foo() {", - " new I(0);", - " }", - "}")); - assertErrors(libraryResult.getCompilationErrors()); - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - DartNewExpression newExpression = findNodeBySource(unit, "new I(0)"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("F(int y)")); - } - - /** - * From specification 0.05, 11/14/2011. - *

- * A constructor kI of I corresponds to a constructor kF of its factory class F if either - *

    - *
  • F does not implement I and kI and kF have the same name, OR - *
  • F implements I and either - *
      - *
    • kI is named NI and kF is named NF , OR - *
    • kI is named NI.id and kF is named NF.id. - *
    - *
- *

- * http://code.google.com/p/dart/issues/detail?id=521 - */ - public void test_resolveInterfaceConstructor_whenFactoryImplementsInterface_nameIsQualified() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - " I.foo(int x);", - "}", - "class F implements I {", - " F.foo(int y) {}", - " factory I.foo(int y) {}", - "}", - "class Test {", - " foo() {", - " new I.foo(0);", - " }", - "}")); - assertErrors(libraryResult.getCompilationErrors()); - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - // "new I.foo()" - good - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.foo(0)"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("F.foo(int y)")); - } - } - - /** - * From specification 0.05, 11/14/2011. - *

- * A constructor kI of I corresponds to a constructor kF of its factory class F if either - *

    - *
  • F does not implement I and kI and kF have the same name, OR - *
  • F implements I and either - *
      - *
    • kI is named NI and kF is named NF , OR - *
    • kI is named NI.id and kF is named NF.id. - *
    - *
- *

- * http://code.google.com/p/dart/issues/detail?id=521 - */ - public void test_resolveInterfaceConstructor_whenFactoryImplementsInterface_negative() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - " I(int x);", - " I.foo(int x);", - "}", - "class F implements I {", - " factory I.foo(int x) {}", - "}", - "class Test {", - " foo() {", - " new I(0);", - " new I.foo(0);", - " }", - "}")); - // Check errors. - { - List errors = libraryResult.getCompilationErrors(); - assertErrors( - errors, - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, 2, 3, 9), - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, 3, 3, 13), - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, 10, 9, 1), - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, 11, 9, 5)); - { - String message = errors.get(0).getMessage(); - assertTrue(message, message.contains("'F'")); - assertTrue(message, message.contains("'F'")); - } - { - String message = errors.get(1).getMessage(); - assertTrue(message, message.contains("'F.foo'")); - assertTrue(message, message.contains("'F'")); - } - } - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - // "new I()" - no such constructor, has other constructors, so no implicit default. - { - DartNewExpression newExpression = findNodeBySource(unit, "new I(0)"); - assertEquals(null, newExpression.getElement()); - } - // "new I.foo()" - would be valid, if not "F implements I", but here invalid - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.foo(0)"); - assertEquals(null, newExpression.getElement()); - } - } - - /** - * From specification 0.05, 11/14/2011. - *

- * A constructor kI of I corresponds to a constructor kF of its factory class F if either - *

    - *
  • F does not implement I and kI and kF have the same name, OR - *
  • F implements I and either - *
      - *
    • kI is named NI and kF is named NF , OR - *
    • kI is named NI.id and kF is named NF.id. - *
    - *
- *

- * http://code.google.com/p/dart/issues/detail?id=521 - */ - public void test_resolveInterfaceConstructor_noFactoryImplementsInterface() throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - " I(int x);", - " I.foo(int x);", - "}", - "class F {", - " F.foo(int y) {}", - " factory I(int y) {}", - " factory I.foo(int y) {}", - "}", - "class Test {", - " foo() {", - " new I(0);", - " new I.foo(0);", - " }", - "}")); - assertErrors(libraryResult.getCompilationErrors()); - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - // "new I()" - { - DartNewExpression newExpression = findNodeBySource(unit, "new I(0)"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("I(int y)")); - } - // "new I.foo()" - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.foo(0)"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("I.foo(int y)")); - } - } - - /** - * From specification 0.05, 11/14/2011. - *

- * A constructor kI of I corresponds to a constructor kF of its factory class F if either - *

    - *
  • F does not implement I and kI and kF have the same name, OR - *
  • F implements I and either - *
      - *
    • kI is named NI and kF is named NF , OR - *
    • kI is named NI.id and kF is named NF.id. - *
    - *
- *

- * http://code.google.com/p/dart/issues/detail?id=521 - */ - public void test_resolveInterfaceConstructor_noFactoryImplementsInterface_negative() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - " I.foo(int x);", - "}", - "class F {", - "}", - "class Test {", - " foo() {", - " new I.foo(0);", - " }", - "}")); - // Check errors. - { - List errors = libraryResult.getCompilationErrors(); - assertErrors( - errors, - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, 2, 3, 13), - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, 8, 9, 5)); - { - String message = errors.get(0).getMessage(); - assertTrue(message, message.contains("'I.foo'")); - assertTrue(message, message.contains("'F'")); - } - } - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - // "new I.foo()" - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.foo(0)"); - assertEquals(null, newExpression.getElement()); - } - } - - /** - * From specification 0.05, 11/14/2011. - *

- * It is a compile-time error if kI and kF do not have the same number of required parameters. - *

- * http://code.google.com/p/dart/issues/detail?id=521 - */ - public void test_resolveInterfaceConstructor_hasByName_negative_notSameNumberOfRequiredParameters() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - " I.foo(int x);", - "}", - "class F implements I {", - " factory F.foo() {}", - "}", - "class Test {", - " foo() {", - " new I.foo();", - " }", - "}")); - assertErrors(libraryResult.getTypeErrors()); - // Check errors. - { - List errors = libraryResult.getCompilationErrors(); - assertErrors( - errors, - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_NUMBER_OF_REQUIRED_PARAMETERS, 2, 3, 13)); - { - String message = errors.get(0).getMessage(); - assertTrue(message, message.contains("'F.foo'")); - assertTrue(message, message.contains("'F'")); - assertTrue(message, message.contains("0")); - assertTrue(message, message.contains("1")); - assertTrue(message, message.contains("'F.foo'")); - } - } - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - // "new I.foo()" - resolved, but we produce error. - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.foo()"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("F.foo()")); - } - } - - /** - * If two members override each other, it is a compile time error if the overriding member has - * fewer optional positional parameters than the member being overridden (7.1). - *

- * http://code.google.com/p/dart/issues/detail?id=521 - */ - public void test_resolveInterfaceConstructor_hasByName_negative_fewerOptionalPositionalParameters() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - " I.foo(int a, [int b, int c]);", - " I.bar(int a, [int b]);", - "}", - "class F implements I {", - " factory F.foo(int any, [int b = 1]) {}", - " factory F.bar(int any) {}", - "}", - "class Test {", - " foo() {", - " new I.foo(0);", - " new I.bar(0);", - " }", - "}")); - assertErrors(libraryResult.getTypeErrors()); - // Check errors. - { - List errors = libraryResult.getCompilationErrors(); - assertErrors( - errors, - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_OPTIONAL_POSITIONAL_PARAMETERS, 2, 3, 29), - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_OPTIONAL_POSITIONAL_PARAMETERS, 3, 3, 22)); - { - String message = errors.get(0).getMessage(); - assertEquals( - "Constructor 'I.foo' in 'I' has 2 optional positional parameters, doesn't match 'F.foo' in 'F' with 1", - message); - } - { - String message = errors.get(1).getMessage(); - assertEquals( - "Constructor 'I.bar' in 'I' has 1 optional positional parameters, doesn't match 'F.bar' in 'F' with 0", - message); - } - } - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - // "new I.foo()" - resolved, but we produce error. - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.foo(0)"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("F.foo(")); - } - // "new I.bar()" - resolved, but we produce error. - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.bar(0)"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("F.bar(")); - } - } - - /** - * If two members override each other, it is a compile time error if the overriding member does - * not have all the named parameters that the member being overridden has (7.1). - *

- * http://code.google.com/p/dart/issues/detail?id=521 - */ - public void test_resolveInterfaceConstructor_hasByName_negative_notSameNamedParameters() - throws Exception { - AnalyzeLibraryResult libraryResult = analyzeLibrary( - "Test.dart", - Joiner.on("\n").join( - "interface I default F {", - " I.foo(int a, {int b, int c});", - " I.bar(int a, {int b, int c});", - " I.baz(int a, {int b});", - "}", - "class F implements I {", - " factory F.foo(int any, {int b: 1}) {}", - " factory F.bar(int any, {int c: 1, int b: 2}) {}", - " factory F.baz(int any, {int c: 1}) {}", - "}", - "class Test {", - " foo() {", - " new I.foo(0);", - " new I.bar(0);", - " new I.baz(0);", - " }", - "}")); - assertErrors(libraryResult.getTypeErrors()); - // Check errors. - { - List errors = libraryResult.getCompilationErrors(); - assertErrors( - errors, - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_NAMED_PARAMETERS, 2, 3, 29), - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_NAMED_PARAMETERS, 3, 3, 29), - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_NAMED_PARAMETERS, 4, 3, 22)); - { - String message = errors.get(0).getMessage(); - assertTrue(message, message.contains("'I.foo'")); - assertTrue(message, message.contains("'F'")); - assertTrue(message, message.contains("[b]")); - assertTrue(message, message.contains("[b, c]")); - assertTrue(message, message.contains("'F.foo'")); - } - { - String message = errors.get(1).getMessage(); - assertTrue(message, message.contains("'I.bar'")); - assertTrue(message, message.contains("'F'")); - assertTrue(message, message.contains("[c, b]")); - assertTrue(message, message.contains("[b, c]")); - assertTrue(message, message.contains("'F.bar'")); - } - { - String message = errors.get(2).getMessage(); - assertTrue(message, message.contains("'I.baz'")); - assertTrue(message, message.contains("'F'")); - assertTrue(message, message.contains("[b]")); - assertTrue(message, message.contains("[c]")); - assertTrue(message, message.contains("'F.baz'")); - } - } - DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next(); - // "new I.foo()" - resolved, but we produce error. - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.foo(0)"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("F.foo(")); - } - // "new I.bar()" - resolved, but we produce error. - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.bar(0)"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("F.bar(")); - } - // "new I.baz()" - resolved, but we produce error. - { - DartNewExpression newExpression = findNodeBySource(unit, "new I.baz(0)"); - ConstructorElement constructorElement = newExpression.getElement(); - assertEquals(true, getElementSource(constructorElement).contains("F.baz(")); - } - } - private static String getElementSource(Element element) throws Exception { SourceInfo sourceInfo = element.getSourceInfo(); // TODO(scheglov) When we will remove Source.getNode(), this null check may be removed diff --git a/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java b/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java index 027a5af7d91..75dfde18f5a 100644 --- a/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java +++ b/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java @@ -177,9 +177,9 @@ public class ResolverTest extends ResolverTestCase { // but the spec mentions no such error resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", - "interface bool {}", - "interface I {", + "class int {}", + "class bool {}", + "abstract class I {", "}", "class A extends C implements I {}", "class B extends C implements I {}", @@ -198,28 +198,6 @@ public class ResolverTest extends ResolverTestCase { */ } - public void testImplicitDefaultConstructor_OnInterfaceWithoutFactory() { - // Check that the implicit constructor is resolved correctly - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface B {}", - "class C { main() { new B(); } }"), - ResolverErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR); - - /* - * We should check for signature mismatch but that is a TypeAnalyzer issue. - */ - } - - public void testImplicitDefaultConstructor_ThroughFactories() { - // Check that we generate implicit constructors through factories also. - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface B default C {}", - "class C {}", - "class D { main() { new B(); } }")); - } - public void testImplicitDefaultConstructor_WithConstCtor() { // Check that we generate an error if the implicit constructor would violate const. resolveAndTest(Joiner.on("\n").join( @@ -272,33 +250,19 @@ public class ResolverTest extends ResolverTestCase { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", - "interface bool {}", + "class int {}", + "class bool {}", "class Cyclic extends Cyclic {", "}", "class A extends B {", "}", "class B extends A {", "}", - "interface I extends I {", - "}", - "class C implements I1, I {", - "}", - "interface I1 {", - "}", - "class D implements I1, I2 {", - "}", - "interface I2 extends I3 {", - "}", - "interface I3 extends I2 {", + "class C implements C {", "}"), ResolverErrorCode.CYCLIC_CLASS, ResolverErrorCode.CYCLIC_CLASS, ResolverErrorCode.CYCLIC_CLASS, - ResolverErrorCode.CYCLIC_CLASS, - ResolverErrorCode.CYCLIC_CLASS, - ResolverErrorCode.CYCLIC_CLASS, - ResolverErrorCode.CYCLIC_CLASS, ResolverErrorCode.CYCLIC_CLASS ); } @@ -313,265 +277,6 @@ public class ResolverTest extends ResolverTestCase { ResolverErrorCode.NO_SUCH_TYPE_CONSTRUCTOR); } - - public void testDefaultTypeArgs1() { - // Type arguments match - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class B implements A {", - " B() {}", - "}")); - } - - public void testDefaultTypeArgs2() { - // Type arguments match - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface A default B {", - "}", - "class B {", - " factory A.construct () {}", - "}")); - } - - public void testDefaultTypeArgs3() { - // Type arguments match - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface A default B {", - "}", - "class B {", - " B() {}", - "}")); - } - - public void testDefaultTypeArgs4() { - // Type arguments match - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface A default B {", - "}", - "class B implements A {", - " B() {}", - "}")); - } - - public void testDefaultTypeArgs5() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - "}", - "class B {", - "}")); - } - - public void testDefaultTypeArgs6() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - "}", - "class B {", - "}")); - } - - public void testDefaultTypeArgs7() { - // Example from spec v0.6 - resolveAndTest(Joiner.on("\n").join( - "class Object{}", - "interface Hashable {}", - "class HashMapImplementation {", - "}", - "interface Map default HashMapImplementation {", - "}")); - } - - public void testDefaultTypeArgs8() { - resolveAndTest(Joiner.on("\n").join( - "class Object{}", - "interface A default B {", - "}", - "class B {", - "}")); - } - - public void testDefaultTypeArgs9() { - resolveAndTest(Joiner.on("\n").join( - "class Object{}", - "interface List {}", - "interface A default B> {}", - "class B> {", - "}")); - } - - public void testDefaultTypeArgs10() { - resolveAndTest(Joiner.on("\n").join( - "class Object{}", - "interface List {}", - "class A {}", - "interface I2 default B {}", - "class B {}", - "")); - } - - - public void testDefaultTypeArgsNew() { - // Invoke constructor in factory method with type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " B();", - "}", - "class C implements A {}", - "class B {", - " factory B() { return new C();}", - "}")); - } - - public void testFactoryBadTypeArgs1() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class C implements A {}", - "class B {", - " factory A() { return new C();}", - "}"), - TypeErrorCode.NO_SUCH_TYPE); - } - - public void testFactoryBadTypeArgs2() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class C implements A {}", - "class B {", - " factory A() { return new C();}", - "}"), - ResolverErrorCode.DEFAULT_CLASS_MUST_HAVE_SAME_TYPE_PARAMS); - } - - public void testFactoryBadTypeArgs3() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class C implements A {}", - "class B {", - " factory A() { return new C();}", - "}"), - ResolverErrorCode.TYPE_PARAMETERS_MUST_MATCH_EXACTLY); - } - - public void testFactoryBadTypeArgs4() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class C implements A {}", - "class B {", - " factory A() { return new C();}", - "}"), - ResolverErrorCode.TYPE_PARAMETERS_MUST_MATCH_EXACTLY, - ResolverErrorCode.TYPE_VARIABLE_DOES_NOT_MATCH); - } - - public void testFactoryBadTypeArgs5() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class C implements A {}", - "class B {", - " factory A() { return new C();}", - "}"), - ResolverErrorCode.TYPE_PARAMETERS_MUST_MATCH_EXACTLY); - } - - public void testFactoryBadTypeArgs6() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class C implements A {}", - "class B {", - " factory A() { return new C();}", - "}"), - ResolverErrorCode.TYPE_VARIABLE_DOES_NOT_MATCH); - } - - public void testFactoryBadTypeArgs7() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class C implements A {}", - "class B {", - " factory A() { return new C();}", - "}"), - ResolverErrorCode.TYPE_PARAMETERS_MUST_MATCH_EXACTLY, - ResolverErrorCode.TYPE_VARIABLE_DOES_NOT_MATCH, - ResolverErrorCode.TYPE_VARIABLE_DOES_NOT_MATCH); - } - - public void testFactoryBadTypeArgs8() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class B {", - " factory A() {}", - "}"), - ResolverErrorCode.TYPE_PARAMETERS_MUST_MATCH_EXACTLY); - } - - public void testFactoryBadTypeArgs9() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class B {", - " factory A() {}", - "}"), - ResolverErrorCode.TYPE_PARAMETERS_MUST_MATCH_EXACTLY); - } - public void test_constFactory() throws Exception { resolveAndTest(Joiner.on("\n").join( "class Object {}", @@ -581,44 +286,6 @@ public class ResolverTest extends ResolverTestCase { errEx(ResolverErrorCode.FACTORY_CANNOT_BE_CONST, 3, 17, 1)); } - public void testFactoryBadTypeArgs11() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default Bogus {", - "}", - "class B {", - "}"), - ResolverErrorCode.NO_SUCH_TYPE); - } - - public void testFactoryBadTypeArgs10() { - // Invoke constructor in factory method with (wrong) type args - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A();", - "}", - "class B {", - " factory A() {}", - "}"), - ResolverErrorCode.DEFAULT_CLASS_MUST_HAVE_SAME_TYPE_PARAMS); - } - - public void testBadDefaultTypeArgs11() { - // Example from spec v0.6 - resolveAndTest(Joiner.on("\n").join( - "class Object{}", - "interface Hashable {}", - "class HashMapImplementation {", - "}", - "interface Map default HashMapImplementation {", - "}"), - ResolverErrorCode.TYPE_PARAMETERS_MUST_MATCH_EXACTLY); - } - public void testBadGenerativeConstructor1() { resolveAndTest(Joiner.on("\n").join( "class Object { }", @@ -640,18 +307,6 @@ public class ResolverTest extends ResolverTestCase { ResolverErrorCode.TOO_MANY_QUALIFIERS_FOR_METHOD); } - public void testBadGenerativeConstructor3() { - resolveAndTest(Joiner.on("\n").join( - "class Object { }", - "interface B { }", - "class A extends B {", - " var val; ", - " B.foo() : this.val = 1;", - "}"), - ResolverErrorCode.NOT_A_CLASS, - ResolverErrorCode.CANNOT_DECLARE_NON_FACTORY_CONSTRUCTOR); - } - public void testGenerativeConstructor() { resolveAndTest(Joiner.on("\n").join( "class Object {}", @@ -750,19 +405,6 @@ public class ResolverTest extends ResolverTestCase { TypeErrorCode.NO_SUCH_TYPE); } - public void testNewExpression6() { - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface int {}", - "interface A default B {", - " A.construct(); ", - "}", - "class B implements A {", - " B() { }", - " factory B.construct() { return new B(); }", - "}")); - } - public void test_noSuchType_field() throws Exception { resolveAndTest(Joiner.on("\n").join( "class Object {}", @@ -857,7 +499,7 @@ public class ResolverTest extends ResolverTestCase { String source = Joiner.on("\n").join( "class Object {}", - "interface Base {}", + "abstract class Base {}", "class MyClass implements Base {", "}"); List errors = resolveAndTest(source, ResolverErrorCode.NO_SUCH_TYPE); @@ -1080,8 +722,8 @@ public class ResolverTest extends ResolverTestCase { public void test_noSuchType_mapLiteral_num_type_args() throws Exception { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", - "interface String {}", + "class int {}", + "class String {}", "class MyClass {", " foo() {", " var map0 = {};", @@ -1248,7 +890,7 @@ public class ResolverTest extends ResolverTestCase { public void testConstClass() { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class GoodBase {", " const GoodBase() : foo = 1;", " final foo;", @@ -1286,7 +928,7 @@ public class ResolverTest extends ResolverTestCase { public void testFinalInit1() { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "final f1 = 1;", "final f2;", // error "class A {", @@ -1343,18 +985,6 @@ public class ResolverTest extends ResolverTestCase { "}")); } - public void testFinalInit6() { - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface I1 {", - " final a;", // not initialized, but in an interface - "}", - "interface I2 {", - " final a;", // not initialized, but in an interface - " C(arg);", - "}")); - } - public void testFinalInit7() { resolveAndTest(Joiner.on("\n").join( "class Object {}", @@ -1376,7 +1006,7 @@ public class ResolverTest extends ResolverTestCase { resolveAndTest(Joiner.on("\n").join( "// filler filler filler filler filler filler filler filler filler filler", "class Object {}", - "interface int {}", + "class int {}", "const f;", ""), errEx(ResolverErrorCode.CONST_REQUIRES_VALUE, 4, 7, 1)); @@ -1434,7 +1064,7 @@ public class ResolverTest extends ResolverTestCase { public void testErrorInUnqualifiedInvocation1() { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class Foo {", " Foo() {}", "}", @@ -1447,7 +1077,7 @@ public class ResolverTest extends ResolverTestCase { public void testErrorInUnqualifiedInvocation2() { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class Foo {}", "method() {", " Foo();", @@ -1458,7 +1088,7 @@ public class ResolverTest extends ResolverTestCase { public void testErrorInUnqualifiedInvocation3() { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class Foo {", " method() {", " T();", @@ -1471,7 +1101,7 @@ public class ResolverTest extends ResolverTestCase { public void testErrorInUnqualifiedInvocation4() { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "typedef int foo();", "method() {", " foo();", @@ -1482,7 +1112,7 @@ public class ResolverTest extends ResolverTestCase { public void testErrorInUnqualifiedInvocation5() { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "method() {", " outer: for(int i = 0; i < 1; i++) {", " outer();", @@ -1581,7 +1211,7 @@ public class ResolverTest extends ResolverTestCase { public void test_redirectConstructor() { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "int topLevel() {}", "class A {", " method() {}", @@ -1627,23 +1257,17 @@ public class ResolverTest extends ResolverTestCase { resolveAndTest(Joiner.on("\n").join( "class Object {}", "class A {", - " abstract A();", - " abstract A.named();", - "}", - "class B {", - " static B() {}", - " static B.named() {}", + " static A() {}", + " static A.named() {}", "}"), - errEx(ResolverErrorCode.CONSTRUCTOR_CANNOT_BE_ABSTRACT, 3, 12, 1), - errEx(ResolverErrorCode.CONSTRUCTOR_CANNOT_BE_ABSTRACT, 4, 12, 7), - errEx(ResolverErrorCode.CONSTRUCTOR_CANNOT_BE_STATIC, 7, 10, 1), - errEx(ResolverErrorCode.CONSTRUCTOR_CANNOT_BE_STATIC, 8, 10, 7)); + errEx(ResolverErrorCode.CONSTRUCTOR_CANNOT_BE_STATIC, 3, 10, 1), + errEx(ResolverErrorCode.CONSTRUCTOR_CANNOT_BE_STATIC, 4, 10, 7)); } public void test_illegalConstructorReturnType() throws Exception { resolveAndTest(Joiner.on("\n").join( "class Object {}", - "interface int {}", + "class int {}", "class A {", " void A();", " void A.named();", @@ -1692,18 +1316,6 @@ public class ResolverTest extends ResolverTestCase { errEx(ResolverErrorCode.CANNOT_CALL_FUNCTION_TYPE_ALIAS, 4, 3, 6)); } - public void test_defaultTargetInterface() throws Exception { - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface A default B {", - " A();", - "}", - "interface B {", - "}"), - errEx(ResolverErrorCode.DEFAULT_MUST_SPECIFY_CLASS, 2, 21, 1), - errEx(ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, 3, 3, 4)); - } - public void test_initializerErrors() { resolveAndTest(Joiner.on("\n").join( "class Object {}", @@ -1721,15 +1333,6 @@ public class ResolverTest extends ResolverTestCase { errEx(ResolverErrorCode.EXPECTED_FIELD_NOT_TYPE_VAR, 8, 12, 1)); } - public void test_noDefaultOnInterface() throws Exception { - resolveAndTest(Joiner.on("\n").join( - "class Object {}", - "interface I {", - " I();", - "}"), - errEx(ResolverErrorCode.ILLEGAL_CONSTRUCTOR_NO_DEFAULT_IN_INTERFACE, 3, 3, 1)); - } - public void test_illegalAccessFromStatic() throws Exception { resolveAndTest(Joiner.on("\n").join( "class Object {}", diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java index 56742bb08a7..aafec2bf47f 100644 --- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java +++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java @@ -36,7 +36,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; @@ -540,83 +539,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { return invocationRef[0]; } - /** - * From specification 0.05, 11/14/2011. - *

- * 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. - *

- * It is a static type warning if the types of named optional parameters with the same name differ - * between kI and kF . - *

- * 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 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 this.fieldName 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. @@ -1621,7 +1543,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 {", @@ -1638,7 +1560,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 {", @@ -1650,14 +1572,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)); } /** @@ -1668,7 +1590,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { AnalyzeLibraryResult result = analyzeLibrary( "abstract class A {", - " abstract foo();", + " foo();", "}", "class B extends A {", " foo({x}) {}", @@ -1683,23 +1605,23 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { public void test_implementsAndOverrides_lessOptionalPositionalParameter() 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_OPTIONAL_PARAMS, 5, 12, 3)); + errEx(ResolverErrorCode.CANNOT_OVERRIDE_METHOD_OPTIONAL_PARAMS, 5, 3, 3)); } public void test_implementsAndOverrides_moreOptionalPositionalParameter() throws Exception { AnalyzeLibraryResult result = analyzeLibrary( "abstract class A {", - " abstract foo([x]);", + " foo([x]);", "}", "abstract class B extends A {", - " abstract foo([a, b]);", + " foo([a, b]);", "}"); assertErrors(result.getErrors()); } @@ -1710,7 +1632,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 {", @@ -1786,7 +1708,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 {", @@ -1829,7 +1751,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 {", @@ -2017,7 +1939,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { AnalyzeLibraryResult result = analyzeLibrary( "// filler filler filler filler filler filler filler filler filler filler", - "interface I { }", + "abstract class I { }", "class A implements I { }", "class B implements I { }"); // static type error B.T not assignable to num assertErrors(result.getErrors(), errEx(TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE, 4, 25, 1)); @@ -3209,10 +3131,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 {", @@ -3788,7 +3710,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 {", + "abstract class Interface {", " T m();", "}", "abstract class A implements Interface {", @@ -3803,7 +3725,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 {", + "abstract class Interface {", " T m();", "}", "abstract class A implements Interface {", @@ -4457,7 +4379,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { " external A() {}", " external factory A.named() {}", " external classMethod() {}", - " external abstract classMethodAbstract();", "}", ""); assertErrors( @@ -4465,8 +4386,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)); } /** @@ -5095,19 +5015,6 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { errEx(ResolverErrorCode.NO_SUCH_TYPE, 2, 23, 1)); } - /** - *

- * 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()); - } - /** *

* http://code.google.com/p/dart/issues/detail?id=5082 diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java index 4774c79e766..c4396fa2c04 100644 --- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java +++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java @@ -303,7 +303,7 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { public void testCyclicTypeVariable() { Map classes = loadSource( - "interface A { }", + "abstract class A { }", "typedef funcType(T arg);", "class B {}", "class C> {}", @@ -335,18 +335,6 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); } - public void testFactory() { - analyzeClasses(loadSource( - "interface Foo default Bar {", - " Foo(String argument);", - "}", - "interface Baz {}", - "class Bar implements Foo, Baz {", - " Bar(String argument) {}", - "}")); - analyzeFail("Baz x = new Foo('');", TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); - } - public void testFieldAccess() { ClassElement element = loadFile("class_with_supertypes.dart").get("ClassWithSupertypes"); assertNotNull("unable to locate ClassWithSupertypes", element); @@ -540,13 +528,13 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { "}", "class C {", "}", - "interface I extends I2 {", + "abstract class I extends I2 {", "}", "class G {", "}", - "interface I1 {", + "abstract class I1 {", "}", - "interface I2 {", + "abstract class I2 {", "}", "class D implements I2 {", "}", @@ -554,7 +542,7 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { "}"); analyzeClasses(classes); assertEquals("[]", object.getAllSupertypes().toString()); - assertEquals("[I, I1, I2, B, C>, Object]", + assertEquals("[B, I, I1, I2, C>, Object]", classes.get("A").getAllSupertypes().toString()); assertEquals("[I, I1, I2, C>, Object]", classes.get("B").getAllSupertypes().toString()); @@ -564,7 +552,7 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { assertEquals("[Object]", classes.get("I1").getAllSupertypes().toString()); assertEquals("[Object]", classes.get("I2").getAllSupertypes().toString()); assertEquals("[I2, Object]", classes.get("D").getAllSupertypes().toString()); - assertEquals("[I2, D, Object]", classes.get("E").getAllSupertypes().toString()); + assertEquals("[I2, D, I2, Object]", classes.get("E").getAllSupertypes().toString()); } public void testIdentifiers() { @@ -592,7 +580,7 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { public void testImplementsAndOverrides() { analyzeClasses(loadSource( - "interface Interface {", + "abstract class Interface {", " void foo(int x);", " void bar();", "}", @@ -620,7 +608,7 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { public void testImplementsAndOverrides2() { analyzeClasses(loadSource( - "interface Interface {", + "abstract class Interface {", " void foo(int x);", "}", // Abstract class not reported until first instantiation. @@ -705,27 +693,6 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { checkSimpleType(string.getType(), "'f${null}sk'"); } - public void testLoadInterfaces() { - loadFile("interfaces.dart"); - ClassElement superElement = (ClassElement)coreElements.get("Super"); - assertNotNull("no element for Super", superElement); - assertEquals(object.getType(), superElement.getSupertype()); - assertEquals(0, superElement.getInterfaces().size()); - ClassElement sub = (ClassElement)coreElements.get("Sub"); - assertNotNull("no element for Sub", sub); - assertEquals(object.getType(), sub.getSupertype()); - assertEquals(1, sub.getInterfaces().size()); - assertEquals(superElement, sub.getInterfaces().get(0).getElement()); - InterfaceType superString = itype(superElement, itype(string)); - InterfaceType subString = itype(sub, itype(string)); - Types types = getTypes(); - assertEquals("Super", String.valueOf(types.asInstanceOf(superString, superElement))); - assertEquals("Super", String.valueOf(types.asInstanceOf(subString, superElement))); - assertEquals("Sub", String.valueOf(types.asInstanceOf(subString, sub))); - assertNull(types.asInstanceOf(superString, sub)); - } - - public void testMapLiteral() { analyze("{ var x = {\"key\": 42}; }"); analyze("{ var x = {'key': 42}; }"); @@ -818,52 +785,6 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { analyze("VoidFunction f = foo() {};"); } - public void testNewExpression() { - analyzeClasses(loadSource( - "class Foo {", - " Foo(int x) {}", - " Foo.foo() {}", - " Foo.bar([int i = null]) {}", - "}", - "interface Bar default Baz {", - " Bar.make();", - "}", - "class Baz {", - " factory Bar.make(T x) { return null; }", - "}", - "class Foobar {", - "}")); - - analyze("Foo x = new Foo(0);"); - analyzeFail("Foo x = new Foo();", TypeErrorCode.MISSING_ARGUMENT); - analyzeFail("Foo x = new Foo('');", TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); - analyzeFail("Foo x = new Foo(0, null);", TypeErrorCode.EXTRA_ARGUMENT); - - analyze("Foo x = new Foo.foo();"); - analyzeFail("Foo x = new Foo.foo(null);", TypeErrorCode.EXTRA_ARGUMENT); - - analyze("Foo x = new Foo.bar();"); - analyze("Foo x = new Foo.bar(0);"); - analyzeFail("Foo x = new Foo.bar('');", TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); - analyzeFail("Foo x = new Foo.bar(0, null);", TypeErrorCode.EXTRA_ARGUMENT); - analyzeFail("var x = new Foobar();", TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); - analyze("Bar x = new Bar.make('');"); - } - - public void testAssignableTypeArg() { - analyzeClasses(loadSource( - "interface Bar default Baz {", - " Bar.make();", - "}", - "class Baz {", - " Baz(T x) { return null; }", - " factory Bar.make(T x) { return null; }", - "}")); - analyze("Baz x = new Baz('');"); - analyze("Bar x = new Bar.make('');"); - analyze("Bar x = new Bar.make('');"); - } - public void testOddStuff() { Map classes = analyzeClasses(loadSource( "class Class {", @@ -939,19 +860,6 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { } } - public void testRawTypes() { - loadFile("interfaces.dart"); - - analyze("{ Sub s; }"); - analyze("{ var s = new Sub(); }"); - analyze("{ Sub s = new Sub(); }"); - analyze("{ Sub s = new Sub(); }"); - analyze("{ Sub s; }"); - analyze("{ var s = new Sub(); }"); - analyze("{ Sub s = new Sub(); }"); - analyze("{ Sub s = new Sub(); }"); - } - public void testReturn() { analyzeFail(returnWithType("int", "'string'"), TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); @@ -1058,17 +966,6 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { analyzeClass(classes.get("B"), 0); } - public void testSuperInterfaces() { - // If this test is failing, first debug any failures in testLoadInterfaces. - loadFile("interfaces.dart"); - analyze("Super s = new Sub();"); - analyze("Super o = new Sub();"); - analyzeFail("Super f1 = new Sub();", - TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); - analyzeFail("Sub f2 = new Sub();", - TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); - } - public void testSwitch() { analyze("{ int i = 27; switch(i) { case i: break; } }"); analyzeFail( @@ -1124,16 +1021,6 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { analyzeIn(cls, "foo() { T t = true; }()", 1); } - public void testDefaultTypeArgs() { - Map source = loadSource( - "class Object{}", - "interface List {}", - "interface A default B> {}", - "class B> {", - "}"); - analyzeClasses(source); - } - public void testUnaryOperators() { Map source = loadSource( "class Foo {", @@ -1356,25 +1243,10 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase { TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); } - public void testValidateFactoryBounds() { - Map source = loadSource( - "class Object {}", - "interface Foo {}", - "interface Bar extends Foo {}", - "interface IA default A { IA(); }", - "class A implements IA {", - " factory A() {}", - "}"); - analyzeClasses(source); - analyze("{ var val1 = new IA(); }"); - analyze("{ var val1 = new IA(); }"); - analyzeFail("{ var val1 = new IA(); }",TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE); - } - public void testStringConcat() { Map source = loadSource( "class Object {}", - "interface Foo {", + "abstract class Foo {", " operator +(arg1);" + "}", "Foo a = new Foo();", diff --git a/compiler/javatests/com/google/dart/compiler/type/class_with_methods.dart b/compiler/javatests/com/google/dart/compiler/type/class_with_methods.dart index 966b943a87b..5f0f4249214 100644 --- a/compiler/javatests/com/google/dart/compiler/type/class_with_methods.dart +++ b/compiler/javatests/com/google/dart/compiler/type/class_with_methods.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface ClassWithMethods { +abstract class ClassWithMethods { untypedNoArgumentMethod(); untypedOneArgumentMethod(argument); untypedTwoArgumentMethod(argument1, argument2); diff --git a/compiler/javatests/com/google/dart/compiler/type/class_with_supertypes.dart b/compiler/javatests/com/google/dart/compiler/type/class_with_supertypes.dart index b08a61466bc..32a67a30094 100644 --- a/compiler/javatests/com/google/dart/compiler/type/class_with_supertypes.dart +++ b/compiler/javatests/com/google/dart/compiler/type/class_with_supertypes.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface Interface { +abstract class Interface { void methodInInterface(); int fieldInInterface; static final int staticFieldInInterface = 1; diff --git a/compiler/javatests/com/google/dart/compiler/type/class_with_type_parameter.dart b/compiler/javatests/com/google/dart/compiler/type/class_with_type_parameter.dart index 48be4d36507..f61bf4ab203 100644 --- a/compiler/javatests/com/google/dart/compiler/type/class_with_type_parameter.dart +++ b/compiler/javatests/com/google/dart/compiler/type/class_with_type_parameter.dart @@ -2,9 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface A {} +abstract class A {} -interface B extends A {} +abstract class B extends A {} class ClassWithTypeParameter { A aField; diff --git a/compiler/javatests/com/google/dart/compiler/type/covariant_class.dart b/compiler/javatests/com/google/dart/compiler/type/covariant_class.dart index 4d485970362..f38bb420ce8 100644 --- a/compiler/javatests/com/google/dart/compiler/type/covariant_class.dart +++ b/compiler/javatests/com/google/dart/compiler/type/covariant_class.dart @@ -2,16 +2,16 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface A { +abstract class A { } -interface B extends A { +abstract class B extends A { } -interface C extends A { +abstract class C extends A { } -interface D { +abstract class D { } class Super { diff --git a/compiler/javatests/com/google/dart/compiler/type/generic_class_with_supertypes.dart b/compiler/javatests/com/google/dart/compiler/type/generic_class_with_supertypes.dart index b96748fe54a..c0ccbb949b1 100644 --- a/compiler/javatests/com/google/dart/compiler/type/generic_class_with_supertypes.dart +++ b/compiler/javatests/com/google/dart/compiler/type/generic_class_with_supertypes.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -interface Interface { +abstract class Interface { I1 interfaceField; I1 interfaceMethod(I2 arg); } diff --git a/compiler/javatests/com/google/dart/compiler/type/interfaces.dart b/compiler/javatests/com/google/dart/compiler/type/interfaces.dart deleted file mode 100644 index deccd201b51..00000000000 --- a/compiler/javatests/com/google/dart/compiler/type/interfaces.dart +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -interface Super {} - -interface Sub extends Super default SubImplementation { - Sub(); -} - -class SubImplementation implements Sub { - SubImplementation() {} -} diff --git a/pkg/dartdoc/lib/mirrors.dart b/pkg/dartdoc/lib/mirrors.dart index d6a80108344..82d48429e8d 100644 --- a/pkg/dartdoc/lib/mirrors.dart +++ b/pkg/dartdoc/lib/mirrors.dart @@ -13,7 +13,7 @@ /** * [Compilation] encapsulates the compilation of a program. */ -class Compilation { +abstract class Compilation { /** * Creates a new compilation which has [script] as its entry point. */ @@ -45,7 +45,7 @@ class Compilation { /** * Returns a future for the compiled JavaScript code. */ - abstract Future compileToJavaScript(); + Future compileToJavaScript(); } /** diff --git a/pkg/dartdoc/lib/src/markdown/block_parser.dart b/pkg/dartdoc/lib/src/markdown/block_parser.dart index 79d9e69f13b..9d09f38d629 100644 --- a/pkg/dartdoc/lib/src/markdown/block_parser.dart +++ b/pkg/dartdoc/lib/src/markdown/block_parser.dart @@ -80,7 +80,7 @@ class BlockParser { } } -class BlockSyntax { +abstract class BlockSyntax { /// Gets the collection of built-in block parsers. To turn a series of lines /// into blocks, each of these will be tried in turn. Order matters here. static List get syntaxes { @@ -114,7 +114,7 @@ class BlockSyntax { return pattern.firstMatch(parser.current) != null; } - abstract Node parse(BlockParser parser); + Node parse(BlockParser parser); List parseChildLines(BlockParser parser) { // Grab all of the lines that form the blockquote, stripping off the ">". @@ -259,10 +259,10 @@ class ListItem { } /// Base class for both ordered and unordered lists. -class ListSyntax extends BlockSyntax { +abstract class ListSyntax extends BlockSyntax { bool get canEndBlock => false; - abstract String get listTag; + String get listTag; Node parse(BlockParser parser) { final items = []; diff --git a/pkg/dartdoc/lib/src/markdown/inline_parser.dart b/pkg/dartdoc/lib/src/markdown/inline_parser.dart index a9588888c93..554477387d7 100644 --- a/pkg/dartdoc/lib/src/markdown/inline_parser.dart +++ b/pkg/dartdoc/lib/src/markdown/inline_parser.dart @@ -148,7 +148,7 @@ class InlineParser { } /// Represents one kind of markdown tag that can be parsed. -class InlineSyntax { +abstract class InlineSyntax { final RegExp pattern; InlineSyntax(String pattern) @@ -168,7 +168,7 @@ class InlineSyntax { return false; } - abstract bool onMatch(InlineParser parser, Match match); + bool onMatch(InlineParser parser, Match match); } /// Matches stuff that should just be passed through as straight text. diff --git a/pkg/intl/lib/src/intl_helpers.dart b/pkg/intl/lib/src/intl_helpers.dart index 95facfdc121..5b29f13b2d0 100644 --- a/pkg/intl/lib/src/intl_helpers.dart +++ b/pkg/intl/lib/src/intl_helpers.dart @@ -39,7 +39,7 @@ class LocaleDataException implements Exception { * An abstract superclass for data readers to keep the type system happy. */ abstract class LocaleDataReader { - abstract Future read(String locale); + Future read(String locale); } /** diff --git a/pkg/unittest/interfaces.dart b/pkg/unittest/interfaces.dart index 9a5d7fbac2d..42c498bdfd2 100644 --- a/pkg/unittest/interfaces.dart +++ b/pkg/unittest/interfaces.dart @@ -28,19 +28,19 @@ typedef String ErrorFormatter(actual, Matcher matcher, String reason, */ abstract class Description { /** Change the value of the description. */ - abstract Description replace(String text); + Description replace(String text); /** This is used to add arbitrary text to the description. */ - abstract Description add(String text); + Description add(String text); /** This is used to add a meaningful description of a value. */ - abstract Description addDescriptionOf(value); + Description addDescriptionOf(value); /** * This is used to add a description of an [Iterable] [list], * with appropriate [start] and [end] markers and inter-element [separator]. */ - abstract Description addAll(String start, String separator, String end, + Description addAll(String start, String separator, String end, Iterable list); } @@ -59,10 +59,10 @@ abstract class Matcher { * and may be used to add details about the mismatch that are too * costly to determine in [describeMismatch]. */ - abstract bool matches(item, MatchState matchState); + bool matches(item, MatchState matchState); /** This builds a textual description of the matcher. */ - abstract Description describe(Description description); + Description describe(Description description); /** * This builds a textual description of a specific mismatch. [item] @@ -74,7 +74,7 @@ abstract class Matcher { * information that is not typically included but can be of help in * diagnosing failures, such as stack traces. */ - abstract Description describeMismatch(item, Description mismatchDescription, + Description describeMismatch(item, Description mismatchDescription, MatchState matchState, bool verbose); } @@ -86,7 +86,7 @@ abstract class Matcher { */ abstract class FailureHandler { /** This handles failures given a textual decription */ - abstract void fail(String reason); + void fail(String reason); /** * This handles failures given the actual [value], the [matcher] @@ -96,7 +96,7 @@ abstract class FailureHandler { * these to create a detailed error message (typically by calling * an [ErrorFormatter]) and then call [fail] with this message. */ - abstract void failMatch(actual, Matcher matcher, String reason, + void failMatch(actual, Matcher matcher, String reason, MatchState matchState, bool verbose); } diff --git a/pkg/unittest/matcher.dart b/pkg/unittest/matcher.dart index d12418533e4..1c430f192fc 100644 --- a/pkg/unittest/matcher.dart +++ b/pkg/unittest/matcher.dart @@ -38,13 +38,13 @@ abstract class BaseMatcher implements Matcher { * [matchState] may be used to return additional info for * the use of [describeMismatch]. */ - abstract bool matches(item, MatchState matchState); + bool matches(item, MatchState matchState); /** * Creates a textual description of a matcher, * by appending to [mismatchDescription]. */ - abstract Description describe(Description mismatchDescription); + Description describe(Description mismatchDescription); /** * Generates a description of the matcher failed for a particular diff --git a/tests/co19/co19-compiler.status b/tests/co19/co19-compiler.status index 6e493016933..779f1ffa937 100644 --- a/tests/co19/co19-compiler.status +++ b/tests/co19/co19-compiler.status @@ -207,7 +207,6 @@ Language/13_Libraries_and_Scripts/1_Imports_A02_t20: Fail, OK Language/13_Libraries_and_Scripts/3_Parts_A02_t04: Fail, OK - Language/13_Libraries_and_Scripts/13_Libraries_and_Scripts_A05_t03: Fail, OK # contains syntax error Language/13_Libraries_and_Scripts/13_Libraries_and_Scripts_A05_t04: Fail, OK # contains syntax error Language/06_Functions/2_Formal_Parameters/2_Optional_Formals_A03_t02: Fail, OK # deprecated parameter syntax diff --git a/tests/language/language.status b/tests/language/language.status index 0549cc37bc4..b3107957c47 100644 --- a/tests/language/language.status +++ b/tests/language/language.status @@ -139,8 +139,6 @@ compile_time_constant10_test/none: Fail # issue 5215. constructor3_negative_test: Fail # Runtime only test, rewrite as multitest constructor_call_wrong_argument_count_negative_test: Fail # Runtime only test, rewrite as multitest disable_privacy_test: Fail # Issue 1882: Needs --disable_privacy support. -duplicate_implements_test/03: Fail, OK # we are going to remove interfaces -duplicate_implements_test/04: Fail, OK # we are going to remove interfaces factory5_test/00: Fail # issue 3079 field_method4_negative_test: Fail # Runtime only test, rewrite as multitest field7_negative_test: Fail, OK # language changed, test issue 5249 @@ -148,7 +146,6 @@ field7a_negative_test: Fail, OK # language changed, test issue 5249 getter_no_setter_test/01: Fail # Fails to detect compile-time error. getter_no_setter2_test/01: Fail # Fails to detect compile-time error. instance_call_wrong_argument_count_negative_test: Fail # Runtime only test, rewrite as multitest -interface_factory1_negative_test: Fail # language change 1031 # Test expects signature of noSuchMethod to be correct according # to specification. Should start working when the library signature # changes. @@ -172,7 +169,6 @@ prefix5_negative_test : Fail # language change 1031 prefix8_negative_test : Fail # language change 1031 prefix9_negative_test : Fail # language change 1031 prefix10_negative_test : Fail # language change 1031 -prefix11_negative_test : Fail # language change 1031 private_member3_negative_test: Fail # Runtime only test? rewrite as multitest pseudo_kw_illegal_test/09: Fail, OK # 'interface' is not a built-in identifier pseudo_kw_illegal_test/14: Fail, OK # 'source' is not a built-in identifier @@ -185,7 +181,6 @@ static_field3_test/04: Fail # http://dartbug.com/5519 syntax_test/none: Fail # Bug 2107 Static type warnings in none case (INSTANTIATION_OF_CLASS_WITH_UNIMPLEMENTED_MEMBERS) throw7_negative_test: Fail # Issue 3654 type_variable_bounds_test/00: Fail # issue 3079 -type_variable_bounds_test/07: Fail # language change 1031 # test issue 5291 type_parameter_test/none: Fail, OK @@ -204,6 +199,89 @@ abstract_factory_constructor_test/none: Fail, OK abstract_syntax_test/none: Fail, OK interface_test/none: Fail, OK +# test issue 6324 +class_test: Fail, OK +compile_time_constant_h_test: Fail, OK +const_constructor_syntax_test/none: Fail, OK +ct_const_test: Fail, OK +cyclic_type_variable_test/none: Fail, OK +cyclic_type_variable_test/01: Fail, OK +cyclic_type_variable_test/02: Fail, OK +cyclic_type_variable_test/03: Fail, OK +cyclic_type_variable_test/04: Fail, OK +default_class_implicit_constructor_test: Fail, OK +default_factory2_test/none: Fail, OK +default_factory2_test/01: Fail, OK +default_factory3_test: Fail, OK +default_factory_library_test: Fail, OK +default_implementation2_test: Fail, OK +default_factory_test: Fail, OK +default_implementation_test: Fail, OK +duplicate_implements_test/none: Fail, OK +duplicate_implements_test/03: Pass +duplicate_implements_test/04: Pass +dynamic_test: Fail, OK +factory2_test: Fail, OK +factory3_test: Fail, OK +factory5_test/none: Fail, OK +factory4_test: Fail, OK +factory_implementation_test: Fail, OK +generic_deep_test: Fail, OK +generic_instanceof3_test: Fail, OK +generic_syntax_test: Fail, OK +implicit_this_test/01: Fail, OK +implicit_this_test/04: Fail, OK +implied_interface_test: Fail, OK +instanceof2_test: Fail, OK +instanceof_test: Fail, OK +interface_constants_test: Fail, OK +interface_factory1_negative_test: Fail, OK +interface_factory_test: Fail, OK +interface_factory_multi_test: Fail, OK +interface_inherit_field_test: Fail, OK +interface_test/00: Fail, OK +is_operator_test: Fail, OK +library_same_name_used_test: Fail, OK +list_literal_syntax_test/none: Fail, OK +method_override2_test/none: Fail, OK +named_parameters_test/none: Fail, OK +non_parameterized_factory2_test: Fail, OK +non_parameterized_factory_test: Fail, OK +prefix11_negative_test: Pass +prefix14_test: Fail, OK +prefix15_test: Fail, OK +prefix16_test: Fail, OK +prefix17_test: Fail, OK +prefix22_test: Fail, OK +prefix23_test: Fail, OK +throw1_test: Fail, OK +throw2_test: Fail, OK +try_catch2_test: Fail, OK +try_catch3_test: Fail, OK +type_checks_in_factory_method_test: Fail, OK +type_variable_bounds2_test/none: Fail, OK +type_variable_bounds2_test/01: Fail, OK +type_variable_bounds2_test/02: Fail, OK +type_variable_bounds2_test/03: Fail, OK +type_variable_bounds2_test/04: Fail, OK +type_variable_bounds2_test/00: Fail, OK +type_variable_bounds2_test/06: Fail, OK +type_variable_bounds_test/none: Fail, OK +type_variable_bounds_test/04: Fail, OK +type_variable_bounds_test/05: Fail, OK +type_variable_bounds_test/02: Fail, OK +type_variable_bounds_test/03: Fail, OK +type_variable_bounds_test/06: Fail, OK +type_variable_bounds_test/01: Fail, OK +type_variable_bounds_test/07: Fail, OK +type_variable_bounds_test/10: Fail, OK +type_variable_bounds_test/09: Fail, OK +type_variable_scope_test/none: Fail, OK +interface_factory1_negative_test: Pass +type_variable_bounds_test/07: Pass + + + # # Add new dartc annotations above in alphabetical order #