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

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

Issue 14668014: Report CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT (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 93e7e8457901770ccd8f3a9beadb71460792ce68..bf0815dc8c82bc77a04e87fa890f2d9bd3870981 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
@@ -111,6 +111,7 @@ import com.google.dart.engine.type.TypeVariableType;
import com.google.dart.engine.utilities.dart.ParameterKind;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
@@ -326,6 +327,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForConflictingConstructorNameAndMember(node);
checkForAllFinalInitializedErrorCodes(node);
checkForMultipleSuperInitializers(node);
+ checkForRecursiveFactoryRedirect(node);
return super.visitConstructorDeclaration(node);
} finally {
isEnclosingConstructorConst = false;
@@ -2193,6 +2195,32 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This checks if the passed constructor declaration has redirected 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_FACTORY_REDIRECT
+ */
+ private boolean checkForRecursiveFactoryRedirect(ConstructorDeclaration node) {
+ // prepare redirected constructor
+ ConstructorName redirectedConstructorNode = node.getRedirectedConstructor();
+ if (redirectedConstructorNode == null) {
+ return false;
+ }
+ // OK if no cycle
+ ConstructorElement element = node.getElement();
+ if (!hasRedirectingFactoryConstructorCycle(element)) {
+ return false;
+ }
+ // report error
+ errorReporter.reportError(
+ CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
+ redirectedConstructorNode);
+ return true;
+ }
+
+ /**
* This checks that the rethrow is inside of a catch clause.
*
* @param node the rethrow expression to evaluate
@@ -2399,6 +2427,22 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * @return {@code true} if the given constructor redirects to itself, directly or indirectly
+ */
+ private boolean hasRedirectingFactoryConstructorCycle(ConstructorElement element) {
+ Set<ConstructorElement> constructors = new HashSet<ConstructorElement>();
+ ConstructorElement current = element;
+ while (current != null) {
+ if (constructors.contains(current)) {
+ return current == element;
+ }
+ constructors.add(current);
+ current = current.getRedirectedConstructor();
+ }
+ return false;
+ }
+
+ /**
* @param node the 'this' expression to analyze
* @return {@code true} if the given 'this' expression is in the valid context
*/

Powered by Google App Engine
This is Rietveld 408576698