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

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

Issue 18810002: Report RETURN_IN_GENERATIVE_CONSTRUCTOR for ExpressionFunctionBody in generative constructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 430642bef06dd1f865d974b857994d6baa337cce..c7e2be7dfa9581fd50d6951836bcf51c08fb19f3 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
@@ -47,6 +47,7 @@ import com.google.dart.engine.ast.FieldDeclaration;
import com.google.dart.engine.ast.FieldFormalParameter;
import com.google.dart.engine.ast.FormalParameter;
import com.google.dart.engine.ast.FormalParameterList;
+import com.google.dart.engine.ast.FunctionBody;
import com.google.dart.engine.ast.FunctionDeclaration;
import com.google.dart.engine.ast.FunctionExpression;
import com.google.dart.engine.ast.FunctionTypeAlias;
@@ -475,6 +476,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
checkForAllRedirectConstructorErrorCodes(node);
checkForUndefinedConstructorInInitializerImplicit(node);
checkForRedirectToNonConstConstructor(node);
+ checkForReturnInGenerativeConstructor(node);
return super.visitConstructorDeclaration(node);
} finally {
isEnclosingConstructorConst = false;
@@ -3906,6 +3908,29 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This checks that if the the given constructor declaration is generative, then it does not have
+ * an expression function body.
+ *
+ * @param node the constructor to evaluate
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR
+ */
+ private boolean checkForReturnInGenerativeConstructor(ConstructorDeclaration node) {
+ // ignore factory
+ if (node.getFactoryKeyword() != null) {
+ return false;
+ }
+ // block body (with possible return statement) is checked elsewhere
+ FunctionBody body = node.getBody();
+ if (!(body instanceof ExpressionFunctionBody)) {
+ return false;
+ }
+ // report error
+ errorReporter.reportError(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, body);
+ return true;
+ }
+
+ /**
* This checks that a type mis-match between the return type and the expressed return type by the
* enclosing method or function.
* <p>
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/CompileTimeErrorCodeTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698