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

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

Issue 10556014: Test for 'if (v as T)' and fix to make 'if as' check useful (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
« 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 2b1c6c5b6077bff1ee6ad84e10bcb8cdb6f842f1..f4589176ec538d411aa0a2e73e515b61c4a91e4d 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -565,23 +565,26 @@ public class TypeAnalyzer implements DartCompilationPhase {
@Override
public Void visitBinaryExpression(DartBinaryExpression node) {
// don't infer type if condition negated
- if (!negation && (node.getOperator() == Token.IS || node.getOperator() == Token.AS)) {
- DartExpression arg1 = node.getArg1();
- DartExpression arg2 = node.getArg2();
- if (arg1 instanceof DartIdentifier && arg1.getElement() instanceof VariableElement
- && arg2 instanceof DartTypeExpression) {
- VariableElement variableElement = (VariableElement) arg1.getElement();
- Type rhsType = arg2.getType();
- Type varType = Types.makeInferred(rhsType);
- variableRestorer.setType(variableElement, varType);
+ if (!negation) {
+ if (node.getOperator() == Token.IS || node.getOperator() == Token.AS) {
+ DartExpression arg1 = node.getArg1();
+ DartExpression arg2 = node.getArg2();
+ if (arg1 instanceof DartIdentifier
+ && arg1.getElement() instanceof VariableElement
+ && arg2 instanceof DartTypeExpression) {
+ VariableElement variableElement = (VariableElement) arg1.getElement();
+ Type rhsType = arg2.getType();
+ Type varType = Types.makeInferred(rhsType);
+ variableRestorer.setType(variableElement, varType);
+ }
}
}
- // visit && expressions
- if (node.getOperator() == Token.AND) {
- return super.visitBinaryExpression(node);
+ // operator || means that we can not be sure about types
+ if (node.getOperator() == Token.OR) {
+ return null;
}
- // other operators, such as || - don't infer types
- return null;
+ // continue
+ return super.visitBinaryExpression(node);
}
});
}
« 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