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

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

Issue 16181004: Report CTEC.REDIRECT_TO_NON_CONST_CONSTRUCTOR (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 48c94210700c96f69ebe21d6ca5175997e9b451b..42022859a8852a912d452e84aeee8ca5b4cc9de5 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
@@ -412,6 +412,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForRecursiveFactoryRedirect(node);
checkForRedirectToInvalidFunction(node);
checkForUndefinedConstructorInInitializerImplicit(node);
+ checkForRedirectToNonConstConstructor(node);
return super.visitConstructorDeclaration(node);
} finally {
isEnclosingConstructorConst = false;
@@ -3211,6 +3212,45 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This checks if the passed constructor declaration has redirected constructor and references
+ * itself directly or indirectly. TODO(scheglov)
+ *
+ * @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#REDIRECT_TO_NON_CONST_CONSTRUCTOR
+ */
+ private boolean checkForRedirectToNonConstConstructor(ConstructorDeclaration node) {
+ // prepare redirected constructor
+ ConstructorName redirectedConstructorNode = node.getRedirectedConstructor();
+ if (redirectedConstructorNode == null) {
+ return false;
+ }
+ // prepare element
+ ConstructorElement element = node.getElement();
+ if (element == null) {
+ return false;
+ }
+ // OK, it is not 'const'
+ if (!element.isConst()) {
+ return false;
+ }
+ // prepare redirected constructor
+ ConstructorElement redirectedConstructor = element.getRedirectedConstructor();
+ if (redirectedConstructor == null) {
+ return false;
+ }
+ // OK, it is also 'const'
+ if (redirectedConstructor.isConst()) {
+ return false;
+ }
+ // report error
+ errorReporter.reportError(
+ CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR,
+ redirectedConstructorNode);
+ return true;
+ }
+
+ /**
* This checks if the passed identifier is banned because it is part of the variable declaration
* with the same name.
*

Powered by Google App Engine
This is Rietveld 408576698