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

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

Issue 18690009: Report CTEC.ARGUMENT_TYPE_NOT_ASSIGNABLE and extra/not-enough arguments as errors. (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
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 2785be68b15c82b7afe5e115aebebf0db727a2c4..e00394b39ef05320c0bb25956bcc507c7e43fcc8 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
@@ -229,6 +229,12 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
private boolean isInCatchClause;
/**
+ * This is set to {@code true} iff the visitor is currently visiting children nodes of an
+ * {@link InstanceCreationExpression}.
+ */
+ private boolean isInConstInstanceCreation;
+
+ /**
* This is set to {@code true} iff the visitor is currently visiting a static variable
* declaration.
*/
@@ -615,21 +621,26 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
@Override
public Void visitInstanceCreationExpression(InstanceCreationExpression node) {
- ConstructorName constructorName = node.getConstructorName();
- TypeName typeName = constructorName.getType();
- Type type = typeName.getType();
- if (type instanceof InterfaceType) {
- InterfaceType interfaceType = (InterfaceType) type;
- checkForConstOrNewWithAbstractClass(node, typeName, interfaceType);
- if (node.isConst()) {
- checkForConstWithNonConst(node);
- checkForConstWithUndefinedConstructor(node);
- checkForConstWithTypeParameters(node);
- } else {
- checkForNewWithUndefinedConstructor(node);
+ isInConstInstanceCreation = node.isConst();
+ try {
+ ConstructorName constructorName = node.getConstructorName();
+ TypeName typeName = constructorName.getType();
+ Type type = typeName.getType();
+ if (type instanceof InterfaceType) {
+ InterfaceType interfaceType = (InterfaceType) type;
+ checkForConstOrNewWithAbstractClass(node, typeName, interfaceType);
+ if (isInConstInstanceCreation) {
+ checkForConstWithNonConst(node);
+ checkForConstWithUndefinedConstructor(node);
+ checkForConstWithTypeParameters(node);
+ } else {
+ checkForNewWithUndefinedConstructor(node);
+ }
}
+ return super.visitInstanceCreationExpression(node);
+ } finally {
+ isInConstInstanceCreation = false;
}
- return super.visitInstanceCreationExpression(node);
}
@Override
@@ -1543,11 +1554,20 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
* @param node the argument to evaluate
* @return {@code true} if and only if an error code is generated on the passed node
* @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
+ * @see CompileTimeErrorCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
*/
private boolean checkForArgumentTypeNotAssignable(Expression argument) {
if (argument == null) {
return false;
}
+
+ ErrorCode errorCode;
+ if (isInConstInstanceCreation || isEnclosingConstructorConst) {
+ errorCode = CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE;
+ } else {
+ errorCode = StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE;
+ }
+
//
// Test static type information
//
@@ -1565,7 +1585,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
return false;
}
errorReporter.reportError(
- StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
+ errorCode,
argument,
staticArgumentType.getDisplayName(),
staticParameterType.getDisplayName());
@@ -1585,7 +1605,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
return false;
}
errorReporter.reportError(
- StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
+ errorCode,
argument,
staticArgumentType.getDisplayName(),
staticParameterType.getDisplayName());
@@ -1599,7 +1619,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
return false;
}
errorReporter.reportError(
- StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
+ errorCode,
argument,
(propagatedArgumentType == null ? staticArgumentType : propagatedArgumentType).getDisplayName(),
(propagatedParameterType == null ? staticParameterType : propagatedParameterType).getDisplayName());

Powered by Google App Engine
This is Rietveld 408576698