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

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

Issue 10910081: Issue 4900. Fix for for-in cycle and field as identifier (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 beccb3422bf5e0d7b8d8a34df66e55a1ae3edd13..8efe4b6af7478b637c8c18c6435859a27ba2bc05 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -1602,13 +1602,17 @@ public class TypeAnalyzer implements DartCompilationPhase {
@Override
public Type visitForInStatement(DartForInStatement node) {
Type variableType;
- VariableElement variableElement;
+ VariableElement variableElement = null;
if (node.introducesVariable()) {
variableType = typeOf(node.getVariableStatement());
variableElement = node.getVariableStatement().getVariables().get(0).getElement();
} else {
variableType = typeOf(node.getIdentifier());
- variableElement = (VariableElement) node.getIdentifier().getElement();
+ // in most cases variable, but sometimes field
+ NodeElement identifierElement = node.getIdentifier().getElement();
+ if (identifierElement instanceof VariableElement) {
+ variableElement = (VariableElement) identifierElement;
+ }
}
// prepare Iterable type
DartExpression iterableExpression = node.getIterable();
@@ -1639,7 +1643,7 @@ public class TypeAnalyzer implements DartCompilationPhase {
// visit body with inferred variable type
VariableElementsRestorer variableRestorer = new VariableElementsRestorer();
try {
- if (elementType != null) {
+ if (variableElement != null && elementType != null) {
variableRestorer.setType(variableElement, elementType);
}
BlockTypeContext blockTypeContext = new BlockTypeContext();
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698