Using 'interface' and 'abstract' for methods should produce error
R=brianwilkerson@google.com BUG= Review URL: https://codereview.chromium.org//11314019 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14165 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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' <type> " +
|
||||
"'catch' '(' <identifier> (',' <identifier>)? ')' 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
|
||||
|
||||
@@ -727,6 +727,21 @@ static FieldElementImplementation fieldFromNode(DartField node,
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <code>true</code> 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 <code>true</code> if given {@link Source} represents code library declaration or
|
||||
|
||||
@@ -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<String> interfaceNames = Elements.getNamedParameters(interfaceConstructor);
|
||||
List<String> 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 <code>true</code> 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.
|
||||
|
||||
@@ -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(
|
||||
|
||||
+6
-39
@@ -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.
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
+2
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<K extends Foo, V> extends Foo {
|
||||
abstract class Bar<K extends Foo, V> implements Foo {
|
||||
}
|
||||
|
||||
interface Bar<K extends Foo, V extends Foo> extends Foo {
|
||||
abstract class Bar<K extends Foo, V extends Foo> implements Foo {
|
||||
}
|
||||
|
||||
interface Bar<K, V extends Foo> extends Foo {
|
||||
abstract class Bar<K, V extends Foo> implements Foo {
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {",
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;",
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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<T> {}
|
||||
|
||||
interface Sub<S> extends Super<S> default SubImplementation<S> {
|
||||
Sub();
|
||||
}
|
||||
|
||||
class SubImplementation<U> implements Sub<U> {
|
||||
SubImplementation() {}
|
||||
}
|
||||
|
||||
class A {
|
||||
main() {
|
||||
Sub<A, A> s = new Sub();
|
||||
Sub<A, A> s2 = new Sub<A>();
|
||||
Sub<A, A> s3;
|
||||
A<A> s4;
|
||||
}
|
||||
}
|
||||
@@ -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<T> default C {}",
|
||||
"abstract class B<T> {}",
|
||||
"class C<T> extends A implements B<T> {}",
|
||||
"class D extends C<int> {}",
|
||||
"class E implements C<int> {}",
|
||||
"class F<T extends A> {}",
|
||||
"class G extends F<C<int>> {}",
|
||||
"interface H<T> default C<T> {}"));
|
||||
"class G extends F<C<int>> {}"));
|
||||
assertErrors(libraryResult.getCompilationErrors());
|
||||
DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next();
|
||||
List<DartNode> 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<T> extends A implements B<T> {}
|
||||
assertNotNull(C.getName().getElement());
|
||||
@@ -193,24 +187,6 @@ public class ResolverCompilerTest extends CompilerTestCase {
|
||||
assertEquals(
|
||||
"int",
|
||||
typeArg.getTypeArguments().get(0).getIdentifier().getElement().getOriginalName());
|
||||
|
||||
// class H<T> extends C<T> {}",
|
||||
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.
|
||||
* <p>
|
||||
* A constructor kI of I corresponds to a constructor kF of its factory class F if either
|
||||
* <ul>
|
||||
* <li>F does not implement I and kI and kF have the same name, OR
|
||||
* <li>F implements I and either
|
||||
* <ul>
|
||||
* <li>kI is named NI and kF is named NF, OR
|
||||
* <li>kI is named NI.id and kF is named NF.id.
|
||||
* </ul>
|
||||
* </ul>
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* A constructor kI of I corresponds to a constructor kF of its factory class F if either
|
||||
* <ul>
|
||||
* <li>F does not implement I and kI and kF have the same name, OR
|
||||
* <li>F implements I and either
|
||||
* <ul>
|
||||
* <li>kI is named NI and kF is named NF , OR
|
||||
* <li>kI is named NI.id and kF is named NF.id.
|
||||
* </ul>
|
||||
* </ul>
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* A constructor kI of I corresponds to a constructor kF of its factory class F if either
|
||||
* <ul>
|
||||
* <li>F does not implement I and kI and kF have the same name, OR
|
||||
* <li>F implements I and either
|
||||
* <ul>
|
||||
* <li>kI is named NI and kF is named NF , OR
|
||||
* <li>kI is named NI.id and kF is named NF.id.
|
||||
* </ul>
|
||||
* </ul>
|
||||
* <p>
|
||||
* 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<DartCompilationError> 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.
|
||||
* <p>
|
||||
* A constructor kI of I corresponds to a constructor kF of its factory class F if either
|
||||
* <ul>
|
||||
* <li>F does not implement I and kI and kF have the same name, OR
|
||||
* <li>F implements I and either
|
||||
* <ul>
|
||||
* <li>kI is named NI and kF is named NF , OR
|
||||
* <li>kI is named NI.id and kF is named NF.id.
|
||||
* </ul>
|
||||
* </ul>
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* A constructor kI of I corresponds to a constructor kF of its factory class F if either
|
||||
* <ul>
|
||||
* <li>F does not implement I and kI and kF have the same name, OR
|
||||
* <li>F implements I and either
|
||||
* <ul>
|
||||
* <li>kI is named NI and kF is named NF , OR
|
||||
* <li>kI is named NI.id and kF is named NF.id.
|
||||
* </ul>
|
||||
* </ul>
|
||||
* <p>
|
||||
* 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<DartCompilationError> 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.
|
||||
* <p>
|
||||
* It is a compile-time error if kI and kF do not have the same number of required parameters.
|
||||
* <p>
|
||||
* 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<DartCompilationError> 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).
|
||||
* <p>
|
||||
* 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<DartCompilationError> 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).
|
||||
* <p>
|
||||
* 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<DartCompilationError> 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
|
||||
|
||||
@@ -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<X> {",
|
||||
"class int {}",
|
||||
"class bool {}",
|
||||
"abstract class I<X> {",
|
||||
"}",
|
||||
"class A extends C implements I<int> {}",
|
||||
"class B extends C implements I<bool> {}",
|
||||
@@ -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<T> default B<T> {",
|
||||
" A();",
|
||||
"}",
|
||||
"class B<T> implements A<T> {",
|
||||
" B() {}",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testDefaultTypeArgs2() {
|
||||
// Type arguments match
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object {}",
|
||||
"interface A<T> default B<T> {",
|
||||
"}",
|
||||
"class B<T> {",
|
||||
" factory A.construct () {}",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testDefaultTypeArgs3() {
|
||||
// Type arguments match
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object {}",
|
||||
"interface A<T> default B<T> {",
|
||||
"}",
|
||||
"class B<T> {",
|
||||
" B() {}",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testDefaultTypeArgs4() {
|
||||
// Type arguments match
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object {}",
|
||||
"interface A<T> default B<T> {",
|
||||
"}",
|
||||
"class B<T> implements A<T> {",
|
||||
" B() {}",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testDefaultTypeArgs5() {
|
||||
// Invoke constructor in factory method with (wrong) type args
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object {}",
|
||||
"interface int {}",
|
||||
"interface A<T> default B {",
|
||||
"}",
|
||||
"class B<T> {",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testDefaultTypeArgs6() {
|
||||
// Invoke constructor in factory method with (wrong) type args
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object {}",
|
||||
"interface int {}",
|
||||
"interface A<T> default B {",
|
||||
"}",
|
||||
"class B<T extends int> {",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testDefaultTypeArgs7() {
|
||||
// Example from spec v0.6
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object{}",
|
||||
"interface Hashable {}",
|
||||
"class HashMapImplementation<K extends Hashable, V> {",
|
||||
"}",
|
||||
"interface Map<K, V> default HashMapImplementation<K extends Hashable, V> {",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testDefaultTypeArgs8() {
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object{}",
|
||||
"interface A<K,V> default B<K, V extends K> {",
|
||||
"}",
|
||||
"class B<K, V extends K> {",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testDefaultTypeArgs9() {
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object{}",
|
||||
"interface List<T> {}",
|
||||
"interface A<K,V> default B<K, V extends List<K>> {}",
|
||||
"class B<K, V extends List<K>> {",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testDefaultTypeArgs10() {
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object{}",
|
||||
"interface List<T> {}",
|
||||
"class A<T, U, V> {}",
|
||||
"interface I2<T> default B<T extends A> {}",
|
||||
"class B<T extends A> {}",
|
||||
""));
|
||||
}
|
||||
|
||||
|
||||
public void testDefaultTypeArgsNew() {
|
||||
// Invoke constructor in factory method with type args
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object {}",
|
||||
"interface int {}",
|
||||
"interface A<T> default B<T> {",
|
||||
" B();",
|
||||
"}",
|
||||
"class C<T> implements A<T> {}",
|
||||
"class B<T> {",
|
||||
" factory B() { return new C<T>();}",
|
||||
"}"));
|
||||
}
|
||||
|
||||
public void testFactoryBadTypeArgs1() {
|
||||
// Invoke constructor in factory method with (wrong) type args
|
||||
resolveAndTest(Joiner.on("\n").join(
|
||||
"class Object {}",
|
||||
"interface int {}",
|
||||
"interface A<T> default B<T> {",
|
||||
" A();",
|
||||
"}",
|
||||
"class C<T> implements A<T> {}",
|
||||
"class B<T> {",
|
||||
" factory A() { return new C<K>();}",
|
||||
"}"),
|
||||
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<T> default B {",
|
||||
" A();",
|
||||
"}",
|
||||
"class C<T> implements A<T> {}",
|
||||
"class B {",
|
||||
" factory A() { return new C<int>();}",
|
||||
"}"),
|
||||
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<T> default B<K> {",
|
||||
" A();",
|
||||
"}",
|
||||
"class C<T> implements A<T> {}",
|
||||
"class B<T> {",
|
||||
" factory A() { return new C<T>();}",
|
||||
"}"),
|
||||
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<T> default B<T> {",
|
||||
" A();",
|
||||
"}",
|
||||
"class C<T> implements A<T> {}",
|
||||
"class B<K> {",
|
||||
" factory A() { return new C<K>();}",
|
||||
"}"),
|
||||
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<T> default B<T,L> {",
|
||||
" A();",
|
||||
"}",
|
||||
"class C<T> implements A<T> {}",
|
||||
"class B<T> {",
|
||||
" factory A() { return new C<T>();}",
|
||||
"}"),
|
||||
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<T> default B<K> {",
|
||||
" A();",
|
||||
"}",
|
||||
"class C<T> implements A<T> {}",
|
||||
"class B<K> {",
|
||||
" factory A() { return new C<K>();}",
|
||||
"}"),
|
||||
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<T,K> default B<T,K> {",
|
||||
" A();",
|
||||
"}",
|
||||
"class C<T,K> implements A<T,K> {}",
|
||||
"class B<K,T> {",
|
||||
" factory A() { return new C<int, Object>();}",
|
||||
"}"),
|
||||
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<T> default B<T> {",
|
||||
" A();",
|
||||
"}",
|
||||
"class B<T extends int> {",
|
||||
" 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<T> default B<T extends int> {",
|
||||
" A();",
|
||||
"}",
|
||||
"class B<T> {",
|
||||
" 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<T> default Bogus {",
|
||||
"}",
|
||||
"class B<T> {",
|
||||
"}"),
|
||||
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<T> 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<K extends Hashable, V> {",
|
||||
"}",
|
||||
"interface Map<K, V> default HashMapImplementation<K, V> {",
|
||||
"}"),
|
||||
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<T> default B<T> {",
|
||||
" A.construct(); ",
|
||||
"}",
|
||||
"class B<T> implements A<T> {",
|
||||
" B() { }",
|
||||
" factory B.construct() { return new B<T>(); }",
|
||||
"}"));
|
||||
}
|
||||
|
||||
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<T> {}",
|
||||
"abstract class Base<T> {}",
|
||||
"class MyClass implements Base<Unknown> {",
|
||||
"}");
|
||||
List<DartCompilationError> 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<T> {",
|
||||
" 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 {}",
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* It is a static type warning if the type of the nth required formal parameter of kI is not
|
||||
* identical to the type of the nth required formal parameter of kF.
|
||||
* <p>
|
||||
* It is a static type warning if the types of named optional parameters with the same name differ
|
||||
* between kI and kF .
|
||||
* <p>
|
||||
* http://code.google.com/p/dart/issues/detail?id=521
|
||||
*/
|
||||
public void test_resolveInterfaceConstructor_hasByName_negative_notSameParametersType()
|
||||
throws Exception {
|
||||
AnalyzeLibraryResult libraryResult =
|
||||
analyzeLibrary(
|
||||
"Test.dart",
|
||||
Joiner.on("\n").join(
|
||||
"interface I default F {",
|
||||
" I.foo(int a, [int b, int c]);",
|
||||
"}",
|
||||
"class F implements I {",
|
||||
" factory F.foo(num any, [bool b, Object c]) {}",
|
||||
"}",
|
||||
"class Test {",
|
||||
" foo() {",
|
||||
" new I.foo(0);",
|
||||
" }",
|
||||
"}"));
|
||||
// No compilation errors.
|
||||
assertErrors(libraryResult.getCompilationErrors());
|
||||
// Check type warnings.
|
||||
{
|
||||
List<DartCompilationError> errors = libraryResult.getTypeErrors();
|
||||
assertErrors(errors, errEx(TypeErrorCode.DEFAULT_CONSTRUCTOR_TYPES, 2, 3, 29));
|
||||
assertEquals(
|
||||
"Constructor 'I.foo' in 'I' has parameters types (int,int,int), doesn't match 'F.foo' in 'F' with (num,bool,Object)",
|
||||
errors.get(0).getMessage());
|
||||
}
|
||||
DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next();
|
||||
// "new I.foo()" - resolved, but we produce error.
|
||||
{
|
||||
DartNewExpression newExpression = findNodeBySource(unit, "new I.foo(0)");
|
||||
DartNode constructorNode = newExpression.getElement().getNode();
|
||||
assertEquals(true, constructorNode.toSource().contains("F.foo("));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* There was problem that <code>this.fieldName</code> constructor parameter had no type, so we
|
||||
* produced incompatible interface/default class warning.
|
||||
*/
|
||||
public void test_resolveInterfaceConstructor_sameParametersType_thisFieldParameter()
|
||||
throws Exception {
|
||||
AnalyzeLibraryResult libraryResult =
|
||||
analyzeLibrary(
|
||||
"Test.dart",
|
||||
Joiner.on("\n").join(
|
||||
"interface I default F {",
|
||||
" I(int a);",
|
||||
"}",
|
||||
"class F implements I {",
|
||||
" int a;",
|
||||
" F(this.a) {}",
|
||||
"}"));
|
||||
// Check that parameter has resolved type.
|
||||
{
|
||||
DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().next();
|
||||
DartClass classF = (DartClass) unit.getTopLevelNodes().get(1);
|
||||
DartMethodDefinition methodF = (DartMethodDefinition) classF.getMembers().get(1);
|
||||
DartParameter parameter = methodF.getFunction().getParameters().get(0);
|
||||
assertEquals("int", parameter.getElement().getType().toString());
|
||||
}
|
||||
// No errors or type warnings.
|
||||
assertErrors(libraryResult.getCompilationErrors());
|
||||
assertErrors(libraryResult.getTypeErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* In contrast, if A is intended to be concrete, the checker should warn about all unimplemented
|
||||
* methods, but allow clients to instantiate it freely.
|
||||
@@ -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<T extends num> { }",
|
||||
"abstract class I<T extends num> { }",
|
||||
"class A<T extends num> implements I<T> { }",
|
||||
"class B<T> implements I<T> { }"); // static type error B.T not assignable to num
|
||||
assertErrors(result.getErrors(), errEx(TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE, 4, 25, 1));
|
||||
@@ -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<T> {",
|
||||
"abstract class Interface<T> {",
|
||||
" 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<T> {",
|
||||
"abstract class Interface<T> {",
|
||||
" T m();",
|
||||
"}",
|
||||
"abstract class A implements Interface<String> {",
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* http://code.google.com/p/dart/issues/detail?id=5084
|
||||
*/
|
||||
public void test_duplicateSuperInterface_okInInterfaceExtends() throws Exception {
|
||||
AnalyzeLibraryResult result = analyzeLibrary(
|
||||
"// filler filler filler filler filler filler filler filler filler filler",
|
||||
"interface A {}",
|
||||
"interface B extends A, A {}",
|
||||
"");
|
||||
assertErrors(result.getErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* http://code.google.com/p/dart/issues/detail?id=5082
|
||||
|
||||
@@ -303,7 +303,7 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase {
|
||||
|
||||
public void testCyclicTypeVariable() {
|
||||
Map<String, ClassNodeElement> classes = loadSource(
|
||||
"interface A<T> { }",
|
||||
"abstract class A<T> { }",
|
||||
"typedef funcType<T>(T arg);",
|
||||
"class B<T extends T> {}",
|
||||
"class C<T extends A<T>> {}",
|
||||
@@ -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<U> {",
|
||||
"}",
|
||||
"interface I<S> extends I2<bool> {",
|
||||
"abstract class I<S> extends I2<bool> {",
|
||||
"}",
|
||||
"class G<V> {",
|
||||
"}",
|
||||
"interface I1<W> {",
|
||||
"abstract class I1<W> {",
|
||||
"}",
|
||||
"interface I2<X> {",
|
||||
"abstract class I2<X> {",
|
||||
"}",
|
||||
"class D implements I2<int> {",
|
||||
"}",
|
||||
@@ -554,7 +542,7 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase {
|
||||
"}");
|
||||
analyzeClasses(classes);
|
||||
assertEquals("[]", object.getAllSupertypes().toString());
|
||||
assertEquals("[I<int>, I1<String>, I2<bool>, B<String>, C<G<String>>, Object]",
|
||||
assertEquals("[B<String>, I<int>, I1<String>, I2<bool>, C<G<String>>, Object]",
|
||||
classes.get("A").getAllSupertypes().toString());
|
||||
assertEquals("[I<int>, I1<B.T>, I2<bool>, C<G<B.T>>, 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<int>, Object]", classes.get("D").getAllSupertypes().toString());
|
||||
assertEquals("[I2<int>, D, Object]", classes.get("E").getAllSupertypes().toString());
|
||||
assertEquals("[I2<int>, D, I2<int>, 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>", String.valueOf(types.asInstanceOf(superString, superElement)));
|
||||
assertEquals("Super<String>", String.valueOf(types.asInstanceOf(subString, superElement)));
|
||||
assertEquals("Sub<String>", 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<T> default Baz<T> {",
|
||||
" Bar.make();",
|
||||
"}",
|
||||
"class Baz<T> {",
|
||||
" factory Bar.make(T x) { return null; }",
|
||||
"}",
|
||||
"class Foobar<T extends String> {",
|
||||
"}"));
|
||||
|
||||
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<num>();", TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE);
|
||||
analyze("Bar<String> x = new Bar.make('');");
|
||||
}
|
||||
|
||||
public void testAssignableTypeArg() {
|
||||
analyzeClasses(loadSource(
|
||||
"interface Bar<T> default Baz<T> {",
|
||||
" Bar.make();",
|
||||
"}",
|
||||
"class Baz<T> {",
|
||||
" Baz(T x) { return null; }",
|
||||
" factory Bar.make(T x) { return null; }",
|
||||
"}"));
|
||||
analyze("Baz<String> x = new Baz<String>('');");
|
||||
analyze("Bar<String> x = new Bar.make('');");
|
||||
analyze("Bar<String> x = new Bar<String>.make('');");
|
||||
}
|
||||
|
||||
public void testOddStuff() {
|
||||
Map<String, ClassNodeElement> 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<String> s = new Sub(); }");
|
||||
analyze("{ Sub<String> s; }");
|
||||
analyze("{ var s = new Sub<String>(); }");
|
||||
analyze("{ Sub s = new Sub<String>(); }");
|
||||
analyze("{ Sub<String> s = new Sub<String>(); }");
|
||||
}
|
||||
|
||||
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<String> s = new Sub<String>();");
|
||||
analyze("Super<Object> o = new Sub<String>();");
|
||||
analyzeFail("Super<String> f1 = new Sub<int>();",
|
||||
TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE);
|
||||
analyzeFail("Sub<String> f2 = new Sub<int>();",
|
||||
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<String, ClassNodeElement> source = loadSource(
|
||||
"class Object{}",
|
||||
"interface List<T> {}",
|
||||
"interface A<K,V> default B<K, V extends List<K>> {}",
|
||||
"class B<K, V extends List<K>> {",
|
||||
"}");
|
||||
analyzeClasses(source);
|
||||
}
|
||||
|
||||
public void testUnaryOperators() {
|
||||
Map<String, ClassNodeElement> source = loadSource(
|
||||
"class Foo {",
|
||||
@@ -1356,25 +1243,10 @@ public class TypeAnalyzerTest extends TypeAnalyzerTestCase {
|
||||
TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE);
|
||||
}
|
||||
|
||||
public void testValidateFactoryBounds() {
|
||||
Map<String, ClassNodeElement> source = loadSource(
|
||||
"class Object {}",
|
||||
"interface Foo {}",
|
||||
"interface Bar extends Foo {}",
|
||||
"interface IA<T> default A<T extends Foo> { IA(); }",
|
||||
"class A<T extends Foo> implements IA<T> {",
|
||||
" factory A() {}",
|
||||
"}");
|
||||
analyzeClasses(source);
|
||||
analyze("{ var val1 = new IA<Foo>(); }");
|
||||
analyze("{ var val1 = new IA<Bar>(); }");
|
||||
analyzeFail("{ var val1 = new IA<String>(); }",TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE);
|
||||
}
|
||||
|
||||
public void testStringConcat() {
|
||||
Map<String, ClassNodeElement> source = loadSource(
|
||||
"class Object {}",
|
||||
"interface Foo {",
|
||||
"abstract class Foo {",
|
||||
" operator +(arg1);" +
|
||||
"}",
|
||||
"Foo a = new Foo();",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<T extends B> {
|
||||
A aField;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<I1, I2> {
|
||||
abstract class Interface<I1, I2> {
|
||||
I1 interfaceField;
|
||||
I1 interfaceMethod(I2 arg);
|
||||
}
|
||||
|
||||
@@ -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<T> {}
|
||||
|
||||
interface Sub<S> extends Super<S> default SubImplementation<S> {
|
||||
Sub();
|
||||
}
|
||||
|
||||
class SubImplementation<U> implements Sub<U> {
|
||||
SubImplementation() {}
|
||||
}
|
||||
@@ -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<String> compileToJavaScript();
|
||||
Future<String> compileToJavaScript();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<BlockSyntax> get syntaxes {
|
||||
@@ -114,7 +114,7 @@ class BlockSyntax {
|
||||
return pattern.firstMatch(parser.current) != null;
|
||||
}
|
||||
|
||||
abstract Node parse(BlockParser parser);
|
||||
Node parse(BlockParser parser);
|
||||
|
||||
List<String> 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 = <ListItem>[];
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user