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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/Resolver.java

Issue 11368132: Issue 6560. Report error when generative constructor calls factory constructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/resolver/Resolver.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/Resolver.java b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
index 91a5f7cdeba75c38bddebffb3023a8c0eb020d35..e159ffca9b37967dbcbaaa3a5b5e6e8d6450abb4 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
@@ -617,6 +617,10 @@ public class Resolver {
ResolverErrorCode.CANNOT_RESOLVE_IMPLICIT_CALL_TO_SUPER_CONSTRUCTOR,
cls.getSuperclass());
}
+ if (superCtor != null && superCtor.getModifiers().isFactory()) {
+ onError(cls.getName(), ResolverErrorCode.NOT_GENERATIVE_SUPER_CONSTRUCTOR, "<default>",
+ supertype);
+ }
}
}
}
@@ -715,7 +719,7 @@ public class Resolver {
&& !(body instanceof DartNativeBlock)) {
resolveInitializers(node, initializedFields);
}
-
+
// resolve redirecting factory constructor
{
DartTypeNode rcTypeName = node.getRedirectedTypeName();
@@ -1177,6 +1181,9 @@ public class Resolver {
} else {
ClassElement classElement = supertype.getElement();
element = Elements.lookupConstructor(classElement, name);
+ if (element != null && element.getModifiers().isFactory()) {
+ onError(x, ResolverErrorCode.NOT_GENERATIVE_SUPER_CONSTRUCTOR, name, supertype);
+ }
if (element == null && "".equals(name) && x.getArguments().isEmpty()
&& Elements.needsImplicitDefaultConstructor(classElement)) {
element = new SyntheticDefaultConstructorElement(null, classElement, typeProvider);
@@ -2218,10 +2225,12 @@ public class Resolver {
}
private void resolveInitializers(DartMethodDefinition node, Set<FieldElement> initializedFields) {
- Iterator<DartInitializer> initializers = node.getInitializers().iterator();
+ ClassElement classElement = (ClassElement) enclosingElement.getEnclosingElement();
+
ConstructorElement constructorElement = null;
- while (initializers.hasNext()) {
- DartInitializer initializer = initializers.next();
+ boolean hasSuperInvocation = false;
+ for (DartInitializer initializer : node.getInitializers()) {
+ hasSuperInvocation |= initializer.getValue() instanceof DartSuperConstructorInvocation;
Element element = resolve(initializer);
if ((ElementKind.of(element) == ElementKind.CONSTRUCTOR) && initializer.isInvocation()) {
constructorElement = (ConstructorElement) element;
@@ -2232,8 +2241,21 @@ public class Resolver {
}
}
+ // If no explicit super() invocation, then implicit call of default super-type constructor.
+ // Check that it is not factory, i.e. generative.
+ if (!hasSuperInvocation && currentHolder instanceof ClassElement) {
+ InterfaceType superType = classElement.getSupertype();
+ if (superType != null) {
+ ClassElement superElement = superType.getElement();
+ ConstructorElement superConstructor = Elements.lookupConstructor(superElement, "");
+ if (superConstructor != null && superConstructor.getModifiers().isFactory()) {
+ onError(node.getName(), ResolverErrorCode.NOT_GENERATIVE_SUPER_CONSTRUCTOR,
+ "<default>", superType);
+ }
+ }
+ }
+
// Look for final fields that are not initialized
- ClassElement classElement = (ClassElement)enclosingElement.getEnclosingElement();
Element methodElement = node.getElement();
if (classElement != null && methodElement != null
&& !classElement.isInterface()
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698