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

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

Issue 15736017: Issue 1015. Report problem for incompatible right operand and index types. (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 862a026d4ba05720cff41a27009f658a2c27c469..82d3aba07ef40f800eb600d1736b0ed270f72a5b 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
@@ -18,6 +18,7 @@ import com.google.dart.engine.ast.ArgumentDefinitionTest;
import com.google.dart.engine.ast.ArgumentList;
import com.google.dart.engine.ast.AssertStatement;
import com.google.dart.engine.ast.AssignmentExpression;
+import com.google.dart.engine.ast.BinaryExpression;
import com.google.dart.engine.ast.BreakStatement;
import com.google.dart.engine.ast.CatchClause;
import com.google.dart.engine.ast.ClassDeclaration;
@@ -48,6 +49,7 @@ import com.google.dart.engine.ast.Identifier;
import com.google.dart.engine.ast.IfStatement;
import com.google.dart.engine.ast.ImplementsClause;
import com.google.dart.engine.ast.ImportDirective;
+import com.google.dart.engine.ast.IndexExpression;
import com.google.dart.engine.ast.InstanceCreationExpression;
import com.google.dart.engine.ast.ListLiteral;
import com.google.dart.engine.ast.MapLiteral;
@@ -329,6 +331,12 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
@Override
+ public Void visitBinaryExpression(BinaryExpression node) {
+ checkForArgumentTypeNotAssignable(node.getRightOperand());
+ return super.visitBinaryExpression(node);
+ }
+
+ @Override
public Void visitCatchClause(CatchClause node) {
boolean previousIsInCatchClause = isInCatchClause;
try {
@@ -516,6 +524,12 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
@Override
+ public Void visitIndexExpression(IndexExpression node) {
+ checkForArgumentTypeNotAssignable(node.getIndex());
+ return super.visitIndexExpression(node);
+ }
+
+ @Override
public Void visitInstanceCreationExpression(InstanceCreationExpression node) {
ConstructorName constructorName = node.getConstructorName();
TypeName typeName = constructorName.getType();
@@ -1411,42 +1425,56 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
boolean problemReported = false;
for (Expression argument : argumentList.getArguments()) {
- // prepare corresponding parameter
- ParameterElement parameterElement = argument.getParameterElement();
- if (parameterElement == null) {
- continue;
- }
- // prepare parameter type
- Type parameterType = parameterElement.getType();
- if (parameterType == null) {
- continue;
- }
- // prepare argument type
- Type argumentType = getBestType(argument);
- if (argumentType == null) {
- continue;
- }
- // OK, argument is assignable
- if (argumentType.isAssignableTo(parameterType)) {
- continue;
- }
- // TODO(scheglov) bug in type algebra?
- if (parameterType.isObject() && argumentType instanceof FunctionType) {
- continue;
- }
- // report problem
- errorReporter.reportError(
- StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
- argument,
- argumentType,
- parameterType);
- problemReported = true;
+ problemReported |= checkForArgumentTypeNotAssignable(argument);
}
// done
return problemReported;
}
/**
+ * This verifies that the passed argument can be assigned to their corresponding parameters.
+ *
+ * @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
+ */
+ private boolean checkForArgumentTypeNotAssignable(Expression argument) {
+ if (argument == null) {
+ return false;
+ }
+ // prepare corresponding parameter
+ ParameterElement parameterElement = argument.getParameterElement();
+ if (parameterElement == null) {
+ return false;
+ }
+ // prepare parameter type
+ Type parameterType = parameterElement.getType();
+ if (parameterType == null) {
+ return false;
+ }
+ // prepare argument type
+ Type argumentType = getBestType(argument);
+ if (argumentType == null) {
+ return false;
+ }
+ // OK, argument is assignable
+ if (argumentType.isAssignableTo(parameterType)) {
+ return false;
+ }
+ // TODO(scheglov) bug in type algebra?
+ if (parameterType.isObject() && argumentType instanceof FunctionType) {
+ return false;
+ }
+ // report problem
+ errorReporter.reportError(
+ StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
+ argument,
+ argumentType,
+ parameterType);
+ return true;
+ }
+
+ /**
* This verifies that left hand side of the passed assignment expression is not final.
*
* @param node the assignment expression to evaluate

Powered by Google App Engine
This is Rietveld 408576698