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

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

Issue 15162010: Report CTEC.RECURSIVE_CONSTRUCTOR_REDIRECT (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Non-error test and status file tweaks 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..37c3a514d3801dcf2b160d364d573a700351a8cf 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
@@ -342,6 +342,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForConflictingConstructorNameAndMember(node);
checkForAllFinalInitializedErrorCodes(node);
checkForMultipleSuperInitializers(node);
+ checkForRecursiveConstructorRedirect(node);
checkForRecursiveFactoryRedirect(node);
checkForRedirectToInvalidFunction(node);
return super.visitConstructorDeclaration(node);
@@ -2308,6 +2309,36 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This checks if the passed constructor declaration is the redirecting generative constructor and
+ * references itself directly or indirectly.
+ *
+ * @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#RECURSIVE_CONSTRUCTOR_REDIRECT
+ */
+ private boolean checkForRecursiveConstructorRedirect(ConstructorDeclaration node) {
+ // we check generative constructor here
+ if (node.getFactoryKeyword() != null) {
+ return false;
+ }
+ // try to find redirecting constructor invocation and analyzer it for recursion
+ for (ConstructorInitializer initializer : node.getInitializers()) {
+ if (initializer instanceof RedirectingConstructorInvocation) {
+ // OK if no cycle
+ ConstructorElement element = node.getElement();
+ if (!hasRedirectingFactoryConstructorCycle(element)) {
+ return false;
+ }
+ // report error
+ errorReporter.reportError(CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT, initializer);
+ return true;
+ }
+ }
+ // OK, no redirecting constructor invocation
+ return false;
+ }
+
+ /**
* This checks if the passed constructor declaration has redirected constructor with compatible
* function type.
*

Powered by Google App Engine
This is Rietveld 408576698