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

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

Issue 10825190: Don't infer non-final field types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tests for 'const' Created 8 years, 4 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 70d4b7d802a5d912c7a4f44a9662fde62351f926..a6f774551e689cd6b1a7018221c7bb35b63ae296 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -576,11 +576,12 @@ public class TypeAnalyzer implements DartCompilationPhase {
* assigned value type is compatible with this propagated type.
*/
private void checkPropagatedTypeCompatible(DartExpression lhsNode, Type rhs) {
- if (lhsNode.getElement() instanceof VariableElement) {
- VariableElement variableElement = (VariableElement) lhsNode.getElement();
- Type variableType = variableElement.getType();
+ Element element = lhsNode.getElement();
+ if (ElementKind.of(element) == ElementKind.VARIABLE
+ || ElementKind.of(element) == ElementKind.FIELD) {
+ Type variableType = element.getType();
if (variableType.isInferred() && !types.isAssignable(variableType, rhs)) {
- Elements.setType(variableElement, dynamicType);
+ Elements.setType(element, dynamicType);
}
}
}
@@ -2521,8 +2522,10 @@ public class TypeAnalyzer implements DartCompilationPhase {
return typeOf(accessor);
} else {
Type result = checkInitializedDeclaration(node, node.getValue());
- // if no type declared for variables, try to use type of value
- {
+ // if no type declared for field, try to use type of value
+ // only final fields, because only in this case we can be sure that field is not assigned
+ // somewhere, may be even not in this unit
+ if (node.getModifiers().isFinal()) {
DartExpression value = node.getValue();
if (value != null) {
Type valueType = value.getType();

Powered by Google App Engine
This is Rietveld 408576698