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

Unified Diff: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java

Issue 10693047: Report type warning on assigning to some types of elements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
diff --git a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
index 2d367b89840ade2eade806945e3d0305d7e66012..209b9b5bebf4d7002ff952ffb694770aa050d497 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -357,6 +357,7 @@ public class TypeAnalyzer implements DartCompilationPhase {
if (!hasInferredType(lhsNode)) {
checkAssignable(rhsNode, lhs, rhs);
}
+ checkAssignableElement(lhsNode);
return rhs;
}
@@ -371,6 +372,7 @@ public class TypeAnalyzer implements DartCompilationPhase {
Token basicOperator = getBasicOperator(node, operator);
Type type = analyzeBinaryOperator(node, lhs, basicOperator, lhsNode, rhsNode);
checkAssignable(node, lhs, type);
+ checkAssignableElement(lhsNode);
return type;
}
@@ -391,6 +393,7 @@ public class TypeAnalyzer implements DartCompilationPhase {
// bit operations, we currently allow them to be used
// if the left-hand-side is of type num.
// TODO(karlklose) find a clean solution, i.e., without a special case for num.
+ checkAssignableElement(lhsNode);
if (lhs.equals(numType)) {
checkAssignable(rhsNode, numType, typeOf(rhsNode));
return intType;
@@ -471,6 +474,30 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
}
+ private void checkAssignableElement(DartExpression lhsNode) {
+ Element lhsElement = lhsNode.getElement();
+ switch (ElementKind.of(lhsElement)) {
+ case DYNAMIC:
+ case VARIABLE:
+ case PARAMETER:
+ case FIELD:
+ case NONE:
+ // OK or unknown
+ break;
+
+ case METHOD:
+ if (lhsElement.getModifiers().isSetter()
+ || lhsElement.getModifiers().isGetter()
+ || lhsElement.getModifiers().isOperator()) {
+ // The check for methods with setters is elsewhere.
+ break;
+ }
+ default:
+ onError(lhsNode, TypeErrorCode.CANNOT_ASSIGN_TO, ElementKind.of(lhsElement));
+ break;
+ }
+ }
+
private void checkStringConcatPlus(DartBinaryExpression binary, Type lhs) {
if (Objects.equal(lhs, stringType)) {
Token operator = binary.getOperator();

Powered by Google App Engine
This is Rietveld 408576698