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

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

Issue 14951006: Report CTEC.FIELD_INITIALIZER_REDIRECTING_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 a5fbfd035407027a233adf343769a431a8bd75c9..31e88938d20b2e49583822b8321b100081ee575e 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
@@ -56,6 +56,7 @@ import com.google.dart.engine.ast.NodeList;
import com.google.dart.engine.ast.NormalFormalParameter;
import com.google.dart.engine.ast.PrefixedIdentifier;
import com.google.dart.engine.ast.PropertyAccess;
+import com.google.dart.engine.ast.RedirectingConstructorInvocation;
import com.google.dart.engine.ast.RethrowExpression;
import com.google.dart.engine.ast.ReturnStatement;
import com.google.dart.engine.ast.SimpleFormalParameter;
@@ -1641,18 +1642,26 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
* @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR
*/
private boolean checkForFieldInitializerOutsideConstructor(FieldFormalParameter node) {
- ASTNode parent = node.getParent();
- if (parent != null) {
- ASTNode grandparent = parent.getParent();
- // If this is not an error case, then parent is a FormalParameterList and the grandparent is a
- // ConstructorDeclaration, or the parent is a DefaultFormalParameter and grandparent is a
- // FormalParameter [with ConstructorDeclaration being its parent],
- if (grandparent != null && !(grandparent instanceof ConstructorDeclaration)
- && !(grandparent.getParent() instanceof ConstructorDeclaration)) {
- errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, node);
+ ConstructorDeclaration constructor = node.getAncestor(ConstructorDeclaration.class);
+ if (constructor == null) {
+ errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, node);
+ return true;
+ }
+ // constructor cannot be a factory
+ if (constructor.getFactoryKeyword() != null) {
+ errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR, node);
+ return true;
+ }
+ // constructor cannot have a redirection
+ for (ConstructorInitializer initializer : constructor.getInitializers()) {
+ if (initializer instanceof RedirectingConstructorInvocation) {
+ errorReporter.reportError(
+ CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR,
+ node);
return true;
}
}
+ // XXX
Brian Wilkerson 2013/05/16 21:13:07 nit: extra comment
return false;
}

Powered by Google App Engine
This is Rietveld 408576698