Updates the resolver to print the line and column number for name conflicts
Along the way I gave the ResoverTest more specific errors to test against and found some cases that weren't being flagged properly as errors. BUG=5415945 Review URL: https://chromereviews.googleplex.com/3544012 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@132 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
@@ -93,7 +93,7 @@ public enum DartCompilerErrorCode implements ErrorCode {
|
||||
FACTORY_CANNOT_BE_CONST("SyntaxError: A factory cannot be const"),
|
||||
FACTORY_CANNOT_BE_STATIC("SyntaxError: A factory cannot be static"),
|
||||
FACTORY_MEMBER_IN_INTERFACE("SyntaxError: factory members are not allowed in interfaces"),
|
||||
FIELD_CONFLICTS("%s conflicts with previously defined %s"),
|
||||
FIELD_CONFLICTS("%s conflicts with previously defined %s at line %d column %d"),
|
||||
FOR_IN_WITH_COMPLEX_VARIABLE("Only simple variables can be assigned to in a for-in construct"),
|
||||
FOR_IN_WITH_MULTIPLE_VARIABLES("Too many variable declarations in a for-in construct"),
|
||||
FOR_IN_WITH_VARIABLE_INITIALIZER("Cannot initialize for-in variables"),
|
||||
@@ -138,7 +138,8 @@ public enum DartCompilerErrorCode implements ErrorCode {
|
||||
MULTIPLE_REST_PARAMETERS("multiple rest parameters"),
|
||||
MULTIPLE_SOURCE_LISTS("'source' may be specified only once"),
|
||||
NAMED_AND_VARIADIC_PARAMETERS("Cannot have both named and variadic parameters"),
|
||||
NAME_CLASSES_EXISTING_MEMBER("name clashes with a previously defined member"),
|
||||
NAME_CLASHES_EXISTING_MEMBER(
|
||||
"name clashes with a previously defined member at %sline %d column %d"),
|
||||
NEW_EXPRESSION_NOT_CONSTRUCTOR("New expression does not resolve to a constructor"),
|
||||
NON_CONST_STATIC_MEMBER_IN_INTERFACE("SyntaxError: non-final static members are not allowed in "
|
||||
+ "interfaces"),
|
||||
|
||||
@@ -287,29 +287,41 @@ public class MemberBuilder {
|
||||
resolveFunction(accessorNode.getFunction(), accessorElement, null);
|
||||
|
||||
String name = fieldNode.getName().getTargetName();
|
||||
Element element = currentHolder.lookupLocalElement(name);
|
||||
FieldElementImplementation fieldElement = null;
|
||||
if (element == null || element.getKind().equals(ElementKind.FIELD)) {
|
||||
fieldElement = (FieldElementImplementation) element;
|
||||
Element element = null;
|
||||
if (currentHolder != null) {
|
||||
element = currentHolder.lookupLocalElement(name);
|
||||
} else {
|
||||
resolutionError(fieldNode, DartCompilerErrorCode.FIELD_CONFLICTS, name, element.getKind());
|
||||
// Top level nodes are not handled gracefully
|
||||
element = topLevelContext.getScope().findElement(name);
|
||||
}
|
||||
|
||||
FieldElementImplementation fieldElement = null;
|
||||
if (element == null || element.getKind().equals(ElementKind.FIELD)
|
||||
&& element.getModifiers().isAbstractField()) {
|
||||
fieldElement = (FieldElementImplementation) element;
|
||||
}
|
||||
|
||||
if (fieldElement == null) {
|
||||
fieldElement = Elements.fieldFromNode(fieldNode, currentHolder, fieldNode.getModifiers());
|
||||
Elements.addField(currentHolder, fieldElement);
|
||||
addField(currentHolder, fieldElement);
|
||||
}
|
||||
|
||||
if (accessorNode.getModifiers().isGetter()) {
|
||||
if (fieldElement.getGetter() != null) {
|
||||
resolutionError(fieldNode, DartCompilerErrorCode.FIELD_CONFLICTS, name, "getter");
|
||||
int conflictLine = fieldElement.getNode().getSourceLine();
|
||||
int conflictColumn = fieldElement.getNode().getSourceColumn();
|
||||
resolutionError(fieldNode, DartCompilerErrorCode.FIELD_CONFLICTS, name, "getter",
|
||||
conflictLine, conflictColumn);
|
||||
} else {
|
||||
fieldElement.setGetter(accessorElement);
|
||||
fieldElement.setType(accessorElement.getReturnType());
|
||||
}
|
||||
} else if (accessorNode.getModifiers().isSetter()) {
|
||||
if (fieldElement.getSetter() != null) {
|
||||
resolutionError(fieldNode, DartCompilerErrorCode.FIELD_CONFLICTS, name, "setter");
|
||||
int conflictLine = fieldElement.getNode().getSourceLine();
|
||||
int conflictColumn = fieldElement.getNode().getSourceColumn();
|
||||
resolutionError(fieldNode, DartCompilerErrorCode.FIELD_CONFLICTS, name, "setter",
|
||||
conflictLine, conflictColumn);
|
||||
} else {
|
||||
fieldElement.setSetter(accessorElement);
|
||||
List<VariableElement> parameters = accessorElement.getParameters();
|
||||
@@ -327,8 +339,10 @@ public class MemberBuilder {
|
||||
}
|
||||
|
||||
private void addField(EnclosingElement holder, FieldElement element) {
|
||||
checkUniqueName(holder, element);
|
||||
Elements.addField(holder, element);
|
||||
if (holder != null) {
|
||||
checkUniqueName(holder, element);
|
||||
Elements.addField(holder, element);
|
||||
}
|
||||
}
|
||||
|
||||
private void addMethod(EnclosingElement holder, MethodElement element) {
|
||||
@@ -412,7 +426,7 @@ public class MemberBuilder {
|
||||
assert e != other : "forgot to call checkUniqueName() before adding to the class?";
|
||||
if (other != null) {
|
||||
ElementKind eKind = ElementKind.of(e);
|
||||
ElementKind oKind = ElementKind.of(other);
|
||||
ElementKind oKind = ElementKind.of(other);
|
||||
|
||||
// Constructors have a separate namespace.
|
||||
boolean oIsConstructor = oKind.equals(ElementKind.CONSTRUCTOR);
|
||||
@@ -442,7 +456,18 @@ public class MemberBuilder {
|
||||
return;
|
||||
}
|
||||
|
||||
resolutionError(e.getNode(), DartCompilerErrorCode.NAME_CLASSES_EXISTING_MEMBER);
|
||||
|
||||
// Message has no space between source and line number so that if we can't
|
||||
// find the name, it won't show funny formatting.
|
||||
String source = "";
|
||||
DartNode otherNode = other.getNode();
|
||||
if (e.getNode() != otherNode && otherNode.getSource() != null
|
||||
&& otherNode.getSource().getUri() != null) {
|
||||
source = otherNode.getSource().getUri().toString() + " ";
|
||||
}
|
||||
|
||||
resolutionError(e.getNode(), DartCompilerErrorCode.NAME_CLASHES_EXISTING_MEMBER,
|
||||
source, other.getNode().getSourceLine(), other.getNode().getSourceColumn());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -14,7 +14,6 @@ import com.google.dart.compiler.DartSourceTest;
|
||||
import com.google.dart.compiler.DefaultCompilerConfiguration;
|
||||
import com.google.dart.compiler.DefaultDartArtifactProvider;
|
||||
import com.google.dart.compiler.MockLibrarySource;
|
||||
import com.google.dart.compiler.ast.DartArrayAccess;
|
||||
import com.google.dart.compiler.ast.DartBinaryExpression;
|
||||
import com.google.dart.compiler.ast.DartClass;
|
||||
import com.google.dart.compiler.ast.DartExprStmt;
|
||||
|
||||
@@ -47,10 +47,10 @@ import com.google.dart.compiler.backend.js.ast.JsThisRef;
|
||||
import com.google.dart.compiler.backend.js.ast.JsThrow;
|
||||
import com.google.dart.compiler.backend.js.ast.JsTry;
|
||||
import com.google.dart.compiler.backend.js.ast.JsVars;
|
||||
import com.google.dart.compiler.backend.js.ast.JsVars.JsVar;
|
||||
import com.google.dart.compiler.backend.js.ast.JsVisitable;
|
||||
import com.google.dart.compiler.backend.js.ast.JsVisitor;
|
||||
import com.google.dart.compiler.backend.js.ast.JsWhile;
|
||||
import com.google.dart.compiler.backend.js.ast.JsVars.JsVar;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
package com.google.dart.compiler.backend.js;
|
||||
|
||||
import com.google.dart.compiler.backend.js.JsToStringGenerationVisitor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.mozilla.javascript.Node;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
package com.google.dart.compiler.backend.js;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.dart.compiler.CompilerConfiguration;
|
||||
import com.google.dart.compiler.CommandLineOptions.CompilerOptions;
|
||||
import com.google.dart.compiler.CompilerConfiguration;
|
||||
import com.google.dart.compiler.CompilerTestCase;
|
||||
import com.google.dart.compiler.DartCompiler;
|
||||
import com.google.dart.compiler.DartCompilerListener;
|
||||
|
||||
@@ -33,7 +33,6 @@ import static com.google.dart.compiler.parser.ParserEventsTest.Mark.FunctionType
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.Identifier;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.IfStatement;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.Initializer;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeExpression;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.Label;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.Literal;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.MapLiteral;
|
||||
@@ -60,6 +59,7 @@ import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TopLevelElem
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TryStatement;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeAnnotation;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeArguments;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeExpression;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeFunctionOrVarable;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.TypeParameter;
|
||||
import static com.google.dart.compiler.parser.ParserEventsTest.Mark.UnaryExpression;
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
package com.google.dart.compiler.resolver;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.DartCompilationError;
|
||||
import com.google.dart.compiler.DartCompilerErrorCode;
|
||||
import com.google.dart.compiler.DartCompilerListener;
|
||||
import com.google.dart.compiler.ErrorCode;
|
||||
import com.google.dart.compiler.ast.DartClass;
|
||||
import com.google.dart.compiler.ast.DartIdentifier;
|
||||
import com.google.dart.compiler.ast.DartNode;
|
||||
@@ -35,14 +38,16 @@ public class ResolverTest extends ResolverTestCase {
|
||||
private final DartClass array = makeClass("Array", makeType("Object"), "E");
|
||||
private final DartClass growableArray = makeClass("GrowableArray", makeType("Array", "S"), "S");
|
||||
private final Types types = Types.getInstance(null);
|
||||
private int expectedErrors = 0;
|
||||
private List<DartCompilationError> encounteredErrors = Lists.newArrayList();
|
||||
|
||||
private void setExpectedErrors(int count) {
|
||||
expectedErrors = count;
|
||||
@Override
|
||||
public void setUp() {
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
}
|
||||
|
||||
private void checkExpectedErrors() {
|
||||
Assert.assertEquals(0, expectedErrors);
|
||||
@Override
|
||||
public void tearDown() {
|
||||
encounteredErrors = null;
|
||||
}
|
||||
|
||||
private ClassElement findElementOrFail(Scope libScope, String elementName) {
|
||||
@@ -140,9 +145,15 @@ public class ResolverTest extends ResolverTestCase {
|
||||
DartClass a = makeClass("A", null, makeTypes("IA"));
|
||||
DartClass b = makeClass("B", null);
|
||||
|
||||
setExpectedErrors(5);
|
||||
Scope libScope = resolve(makeUnit(object, ia, ib, ic, id, a, b), getContext());
|
||||
checkExpectedErrors();
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
|
||||
ClassElement elementIA = findElementOrFail(libScope, "IA");
|
||||
ClassElement elementIB = findElementOrFail(libScope, "IB");
|
||||
@@ -167,9 +178,13 @@ public class ResolverTest extends ResolverTestCase {
|
||||
DartClass ia = makeInterface("IA", makeTypes("IB"), null);
|
||||
DartClass ib = makeInterface("IB", makeTypes("IA"), null);
|
||||
|
||||
setExpectedErrors(2);
|
||||
|
||||
Scope libScope = resolve(makeUnit(object, ia, ib), getContext());
|
||||
checkExpectedErrors();
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
|
||||
ClassElement elementIA = findElementOrFail(libScope, "IA");
|
||||
ClassElement elementIB = findElementOrFail(libScope, "IB");
|
||||
@@ -198,7 +213,6 @@ public class ResolverTest extends ResolverTestCase {
|
||||
}
|
||||
|
||||
public void testDuplicatedInterfaces() {
|
||||
setExpectedErrors(1);
|
||||
resolve(parseUnit(
|
||||
"class Object {}",
|
||||
"interface int {}",
|
||||
@@ -211,7 +225,8 @@ public class ResolverTest extends ResolverTestCase {
|
||||
"}",
|
||||
"class C implements I<int> {",
|
||||
"}"), getContext());
|
||||
checkExpectedErrors();
|
||||
ErrorCode[] expected = { DartCompilerErrorCode.DUPLICATED_INTERFACE };
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
public void testImplicitDefaultConstructor() {
|
||||
@@ -220,8 +235,10 @@ public class ResolverTest extends ResolverTestCase {
|
||||
"class Object {}",
|
||||
"class B {}",
|
||||
"class C { main() { new B(); } }"), getContext());
|
||||
checkExpectedErrors();
|
||||
|
||||
{
|
||||
ErrorCode[] expected = {};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
/*
|
||||
* We should check for signature mismatch but that is a TypeAnalyzer issue.
|
||||
*/
|
||||
@@ -234,18 +251,25 @@ public class ResolverTest extends ResolverTestCase {
|
||||
"interface B factory C {}",
|
||||
"class C {}",
|
||||
"class D { main() { new B(); } }"), getContext());
|
||||
checkExpectedErrors();
|
||||
{
|
||||
ErrorCode[] expected = {};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testImplicitDefaultConstructor_WithConstCtor() {
|
||||
setExpectedErrors(1);
|
||||
// Check that we generate an error if the implicit constructor would violate const.
|
||||
resolve(parseUnit(
|
||||
"class Object {}",
|
||||
"class B { const B() {} }",
|
||||
"class C extends B {}",
|
||||
"class D { main() { new C(); } }"), getContext());
|
||||
checkExpectedErrors();
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.CONST_CONSTRUCTOR_CANNOT_HAVE_BODY,
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
}
|
||||
|
||||
public void testImplicitSuperCall_ImplicitCtor() {
|
||||
@@ -255,7 +279,10 @@ public class ResolverTest extends ResolverTestCase {
|
||||
"class B { B() {} }",
|
||||
"class C extends B {}",
|
||||
"class D { main() { new C(); } }"), getContext());
|
||||
checkExpectedErrors();
|
||||
{
|
||||
ErrorCode[] expected = {};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
}
|
||||
|
||||
public void testImplicitSuperCall_OnExistingCtor() {
|
||||
@@ -265,22 +292,29 @@ public class ResolverTest extends ResolverTestCase {
|
||||
"class B { B() {} }",
|
||||
"class C extends B { C(){} }",
|
||||
"class D { main() { new C(); } }"), getContext());
|
||||
checkExpectedErrors();
|
||||
{
|
||||
ErrorCode[] expected = {};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
}
|
||||
|
||||
public void testImplicitSuperCall_NonExistentSuper() {
|
||||
setExpectedErrors(1);
|
||||
// Check that we generate an error if the implicit constructor would call a non-existent super.
|
||||
resolve(parseUnit(
|
||||
"class Object {}",
|
||||
"class B { B(Object o) {} }",
|
||||
"class C extends B {}",
|
||||
"class D { main() { new C(); } }"), getContext());
|
||||
checkExpectedErrors();
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.CANNOT_RESOLVE_IMPLICIT_CALL_TO_SUPER_CONSTRUCTOR
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
}
|
||||
|
||||
public void testCyclicSupertype() {
|
||||
setExpectedErrors(8);
|
||||
|
||||
resolve(parseUnit(
|
||||
"class Object {}",
|
||||
"interface int {}",
|
||||
@@ -303,33 +337,46 @@ public class ResolverTest extends ResolverTestCase {
|
||||
"}",
|
||||
"interface I3 extends I2 {",
|
||||
"}"), getContext());
|
||||
checkExpectedErrors();
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
DartCompilerErrorCode.CYCLIC_CLASS,
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
|
||||
}
|
||||
|
||||
public void testBadFactory() {
|
||||
setExpectedErrors(1);
|
||||
resolve(parseUnit("class Object {}",
|
||||
"class Zebra {",
|
||||
" factory foo() {}",
|
||||
"}"), getContext());
|
||||
checkExpectedErrors();
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.NO_SUCH_TYPE
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a class may implement the implied interface of another class and that interfaces may
|
||||
* extend the implied interface of a class.
|
||||
*
|
||||
* @throws DuplicatedInterfaceException
|
||||
* @throws CyclicDeclarationException
|
||||
*
|
||||
* @throws DuplicatedInterfaceException
|
||||
* @throws CyclicDeclarationException
|
||||
*/
|
||||
public void testImpliedInterfaces() throws CyclicDeclarationException,
|
||||
DuplicatedInterfaceException {
|
||||
DartClass a = makeClass("A", null);
|
||||
DartClass b = makeClass("B", null, makeTypes("A"));
|
||||
DartClass ia = makeInterface("IA", makeTypes("B"), null);
|
||||
setExpectedErrors(0);
|
||||
Scope libScope = resolve(makeUnit(object, a, b, ia), getContext());
|
||||
checkExpectedErrors();
|
||||
ErrorCode[] expected = {};
|
||||
checkExpectedErrors(expected);
|
||||
|
||||
ClassElement elementA = findElementOrFail(libScope, "A");
|
||||
ClassElement elementB = findElementOrFail(libScope, "B");
|
||||
@@ -342,13 +389,175 @@ public class ResolverTest extends ResolverTestCase {
|
||||
}
|
||||
|
||||
public void testUnresolvedSuper() {
|
||||
setExpectedErrors(0);
|
||||
resolve(parseUnit(
|
||||
"class Object {}",
|
||||
"class Foo {",
|
||||
" foo() { super.foo(); }",
|
||||
"}"), getContext());
|
||||
checkExpectedErrors();
|
||||
ErrorCode[] expected = {};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
public void testNameConflict() {
|
||||
resolve(parseUnit("class Object {}",
|
||||
"class A {",
|
||||
" var foo;",
|
||||
" var foo;",
|
||||
"}"),
|
||||
getContext());
|
||||
ErrorCode[] expected1 = {
|
||||
DartCompilerErrorCode.NAME_CLASHES_EXISTING_MEMBER
|
||||
};
|
||||
checkExpectedErrors(expected1);
|
||||
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"class A {",
|
||||
" foo() {}",
|
||||
" set foo(x) {}",
|
||||
"}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.NAME_CLASHES_EXISTING_MEMBER
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
// Same test, but reverse the order of setter and method
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"class A {",
|
||||
" set foo(x) {}",
|
||||
" foo() {}",
|
||||
"}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.NAME_CLASHES_EXISTING_MEMBER
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"class A {",
|
||||
" var foo;",
|
||||
" set foo(x) {}",
|
||||
"}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.NAME_CLASHES_EXISTING_MEMBER
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"class A {",
|
||||
" get foo() {}",
|
||||
" var foo;",
|
||||
"}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.NAME_CLASHES_EXISTING_MEMBER
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"class A {",
|
||||
" var foo;",
|
||||
" get foo() {}",
|
||||
"}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.NAME_CLASHES_EXISTING_MEMBER
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"class A {",
|
||||
" set foo(x) {}",
|
||||
" var foo;",
|
||||
"}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.NAME_CLASHES_EXISTING_MEMBER
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"get foo() {}",
|
||||
"class foo {}",
|
||||
"set bar(x) {}",
|
||||
"class bar {}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
// Same test but in different order
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"class foo {}",
|
||||
"get foo() {}",
|
||||
"class bar {}",
|
||||
"set bar(x) {}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"set bar(x) {}",
|
||||
"set bar(x) {}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.FIELD_CONFLICTS,
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
|
||||
encounteredErrors = Lists.newArrayList();
|
||||
resolve(parseUnit("class Object {}",
|
||||
"get bar() {}",
|
||||
"get bar() {}"),
|
||||
getContext());
|
||||
{
|
||||
ErrorCode[] expected = {
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.DUPLICATE_DEFINITION,
|
||||
DartCompilerErrorCode.FIELD_CONFLICTS,
|
||||
};
|
||||
checkExpectedErrors(expected);
|
||||
}
|
||||
}
|
||||
|
||||
private static DartUnit makeUnit(DartNode... topLevelElements) {
|
||||
@@ -389,12 +598,7 @@ public class ResolverTest extends ResolverTestCase {
|
||||
return new DartCompilerListener() {
|
||||
@Override
|
||||
public void compilationError(DartCompilationError event) {
|
||||
expectedErrors--;
|
||||
if (expectedErrors < 0) {
|
||||
AssertionError error = new AssertionError(event.getMessage());
|
||||
error.initCause(event.getException());
|
||||
throw error;
|
||||
}
|
||||
encounteredErrors.add(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,13 +617,38 @@ public class ResolverTest extends ResolverTestCase {
|
||||
return new TestCompilerContext() {
|
||||
@Override
|
||||
public void compilationError(DartCompilationError event) {
|
||||
expectedErrors--;
|
||||
if (expectedErrors < 0) {
|
||||
AssertionError error = new AssertionError(event.getMessage());
|
||||
error.initCause(event.getException());
|
||||
throw error;
|
||||
}
|
||||
encounteredErrors.add(event);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private boolean checkExpectedErrors(ErrorCode[] errorCodes) {
|
||||
if (errorCodes.length != encounteredErrors.size()) {
|
||||
printEncountered();
|
||||
assertEquals(errorCodes.length, encounteredErrors.size());
|
||||
}
|
||||
int index = 0;
|
||||
for (ErrorCode errorCode : errorCodes) {
|
||||
ErrorCode found = encounteredErrors.get(index).getErrorCode();
|
||||
if (!found.equals(errorCode)) {
|
||||
printEncountered();
|
||||
assertEquals("Unexpected Error Code: ", errorCode, found);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* For debugging.
|
||||
*/
|
||||
private void printEncountered() {
|
||||
for (DartCompilationError error : encounteredErrors) {
|
||||
DartCompilerErrorCode errorCode = (DartCompilerErrorCode) error
|
||||
.getErrorCode();
|
||||
String msg = String.format("%s > %s (%d:%d)", errorCode.name(), error
|
||||
.getMessage(), error.getLineNumber(), error.getColumnNumber());
|
||||
System.out.println(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.dart.compiler.parser.DartParser;
|
||||
import com.google.dart.compiler.parser.DartScannerParserContext;
|
||||
import com.google.dart.compiler.parser.Token;
|
||||
import com.google.dart.compiler.resolver.ClassElement;
|
||||
import com.google.dart.compiler.resolver.TopLevelElementBuilder;
|
||||
import com.google.dart.compiler.resolver.CoreTypeProvider;
|
||||
import com.google.dart.compiler.resolver.CyclicDeclarationException;
|
||||
import com.google.dart.compiler.resolver.DuplicatedInterfaceException;
|
||||
@@ -33,6 +32,7 @@ import com.google.dart.compiler.resolver.Resolver;
|
||||
import com.google.dart.compiler.resolver.Resolver.ResolveElementsVisitor;
|
||||
import com.google.dart.compiler.resolver.Scope;
|
||||
import com.google.dart.compiler.resolver.SupertypeResolver;
|
||||
import com.google.dart.compiler.resolver.TopLevelElementBuilder;
|
||||
import com.google.dart.compiler.util.DartSourceString;
|
||||
|
||||
import java.io.IOError;
|
||||
|
||||
@@ -80,7 +80,6 @@ NamedParameters3NegativeTest: Fail # Implementation in progress.
|
||||
NamedParameters4NegativeTest: Fail # Implementation in progress.
|
||||
NamedParameters6NegativeTest: Crash # Implementation in progress.
|
||||
ScopeVariableTest: Fail # 5244704
|
||||
Field1NegativeTest: Fail # 5253031
|
||||
InstFieldInitializerTest: Fail # Cannot deal with static final values in const expression.
|
||||
RegExp3Test: Fail # 5299683
|
||||
InterfaceFactory3NegativeTest: Fail # 5387405
|
||||
|
||||
Reference in New Issue
Block a user