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

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

Issue 15095009: Report CTEC.CONST_WITH_TYPE_PARAMETERS (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 0bc0c09e965b7288f43e28fcbd78b4d62720cc2e..aa95d84968d2d7ae56b9124179c91f65979077b8 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
@@ -430,6 +430,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
if (node.isConst()) {
checkForConstWithNonConst(node);
checkForConstWithUndefinedConstructor(node);
+ checkForConstWithTypeParameters(node);
} else {
checkForNewWithUndefinedConstructor(node);
}
@@ -1222,7 +1223,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
* This verifies that the passed 'const' instance creation expression is not being invoked on a
* constructor that is not 'const'.
* <p>
- * This method assumes that the instance creation was tested to be 'setter' before being called.
+ * This method assumes that the instance creation was tested to be 'const' before being called.
*
* @param node the instance creation expression to evaluate
* @return {@code true} if and only if an error code is generated on the passed node
@@ -1238,10 +1239,62 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * This verifies that the passed 'const' instance creation expression does not reference any type
+ * parameters.
+ * <p>
+ * This method assumes that the instance creation was tested to be 'const' before being called.
+ *
+ * @param node the instance creation expression to evaluate
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS
+ */
+ private boolean checkForConstWithTypeParameters(InstanceCreationExpression node) {
+ ConstructorName constructorName = node.getConstructorName();
+ if (constructorName == null) {
+ return false;
+ }
+ TypeName typeName = constructorName.getType();
+ return checkForConstWithTypeParameters(typeName);
+ }
+
+ /**
+ * This verifies that the passed type name does not reference any type parameters.
+ *
+ * @param typeName the type name to evaluate
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS
+ */
+ private boolean checkForConstWithTypeParameters(TypeName typeName) {
+ // something wrong with AST
+ if (typeName == null) {
+ return false;
+ }
+ Identifier name = typeName.getName();
+ if (name == null) {
+ return false;
+ }
+ // should not be a type parameter
+ if (name.getElement() instanceof TypeVariableElement) {
+ errorReporter.reportError(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, name);
+ }
+ // check type arguments
+ TypeArgumentList typeArguments = typeName.getTypeArguments();
+ if (typeArguments != null) {
+ boolean hasError = false;
+ for (TypeName argument : typeArguments.getArguments()) {
+ hasError |= checkForConstWithTypeParameters(argument);
+ }
+ return hasError;
+ }
+ // OK
+ return false;
+ }
+
+ /**
* This verifies that if the passed 'const' instance creation expression is being invoked on the
* resolved constructor.
* <p>
- * This method assumes that the instance creation was tested to be 'setter' before being called.
+ * This method assumes that the instance creation was tested to be 'const' before being called.
*
* @param node the instance creation expression to evaluate
* @return {@code true} if and only if an error code is generated on the passed node

Powered by Google App Engine
This is Rietveld 408576698