| 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();
|
|
|