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

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java

Issue 14856021: Report UNDEFINED_CONSTRUCTOR_IN_INITIALIZER and others (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
index 68e94b7e18af32d73abd37f3d8c81b74b843e3cd..6bb3a3e57ec4ffb41f5ff7759c2cb15493cf3ea6 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
@@ -344,6 +344,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForMultipleSuperInitializers(node);
checkForRecursiveFactoryRedirect(node);
checkForRedirectToInvalidFunction(node);
+ checkForUndefinedConstructorInInitializerImplicit(node);
return super.visitConstructorDeclaration(node);
} finally {
isEnclosingConstructorConst = false;
@@ -2498,6 +2499,55 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This checks that if the passed generative constructor has no explicit super constructor
+ * invocation, then super class has the default generative constructor.
+ *
+ * @param node the constructor declaration to evaluate
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT
+ * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR
+ */
+ private boolean checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration node) {
+ // ignore if not generative
+ if (node.getFactoryKeyword() != null) {
+ return false;
+ }
+ // prepare "super"
+ if (enclosingClass == null) {
+ return false;
+ }
+ InterfaceType superType = enclosingClass.getSupertype();
+ if (superType == null) {
+ return false;
+ }
+ ClassElement superElement = superType.getElement();
+ // has implicit super constructor invocation
+ for (ConstructorInitializer constructorInitializer : node.getInitializers()) {
+ if (constructorInitializer instanceof SuperConstructorInvocation) {
+ return false;
+ }
+ }
+ // OK, super class has unnamed constructor
+ ConstructorElement superDefaultConstructor = superElement.getUnnamedConstructor();
+ if (superDefaultConstructor != null) {
+ if (superDefaultConstructor.isFactory()) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
+ node.getReturnType(),
+ superDefaultConstructor);
+ return true;
+ }
+ return false;
+ }
+ // report error
+ errorReporter.reportError(
+ CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT,
+ node.getReturnType(),
+ superElement.getName());
+ return true;
+ }
+
+ /**
* This verifies the passed operator-method declaration, has correct number of parameters.
* <p>
* This method assumes that the method declaration was tested to be an operator declaration before

Powered by Google App Engine
This is Rietveld 408576698