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

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

Issue 14861012: Report CTEC.CONST_WITH_NON_CONSTANT_ARGUMENT (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/ConstantVerifier.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ConstantVerifier.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ConstantVerifier.java
index fabefc250277306119d145f4cb5e9e9e2b24bbbb..98c4311a5779ffa788675660af9976791f1fce7b 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ConstantVerifier.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ConstantVerifier.java
@@ -13,15 +13,18 @@
*/
package com.google.dart.engine.internal.verifier;
+import com.google.dart.engine.ast.ArgumentList;
import com.google.dart.engine.ast.DefaultFormalParameter;
import com.google.dart.engine.ast.Expression;
import com.google.dart.engine.ast.FormalParameter;
import com.google.dart.engine.ast.FormalParameterList;
import com.google.dart.engine.ast.FunctionExpression;
+import com.google.dart.engine.ast.InstanceCreationExpression;
import com.google.dart.engine.ast.ListLiteral;
import com.google.dart.engine.ast.MapLiteral;
import com.google.dart.engine.ast.MapLiteralEntry;
import com.google.dart.engine.ast.MethodDeclaration;
+import com.google.dart.engine.ast.NamedExpression;
import com.google.dart.engine.ast.SwitchCase;
import com.google.dart.engine.ast.VariableDeclaration;
import com.google.dart.engine.ast.visitor.RecursiveASTVisitor;
@@ -68,6 +71,12 @@ public class ConstantVerifier extends RecursiveASTVisitor<Void> {
}
@Override
+ public Void visitInstanceCreationExpression(InstanceCreationExpression node) {
+ validateConstantArguments(node);
+ return super.visitInstanceCreationExpression(node);
+ }
+
+ @Override
public Void visitListLiteral(ListLiteral node) {
super.visitListLiteral(node);
if (node.getModifier() != null) {
@@ -201,6 +210,28 @@ public class ConstantVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * Validate that if the passed instance creation is 'const' then all its arguments are constant
+ * expressions.
+ *
+ * @param node the instance creation evaluate
+ */
+ private void validateConstantArguments(InstanceCreationExpression node) {
+ if (!node.isConst()) {
+ return;
+ }
+ ArgumentList argumentList = node.getArgumentList();
+ if (argumentList == null) {
+ return;
+ }
+ for (Expression argument : argumentList.getArguments()) {
+ if (argument instanceof NamedExpression) {
+ argument = ((NamedExpression) argument).getExpression();
+ }
+ validate(argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT);
+ }
+ }
+
+ /**
* Validate that the default value associated with each of the parameters in the given list is a
* compile time constant.
*

Powered by Google App Engine
This is Rietveld 408576698