Don't infer non-final field types

We can not analyze universe and prove that field is not reassigned to have value of othe type.

R=brianwilkerson@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10825190

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10260 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
scheglov@google.com
2012-08-03 22:10:39 +00:00
parent eec0cd7855
commit c0e823e0f7
3 changed files with 66 additions and 15 deletions
@@ -678,7 +678,7 @@ public class Resolver {
// Now, this constant has a type. Save it for future reference.
Element element = node.getElement();
Type expressionType = expression.getType();
if (expressionType != null && TypeKind.of(element.getType()) == TypeKind.DYNAMIC) {
if (isFinal && expressionType != null && TypeKind.of(element.getType()) == TypeKind.DYNAMIC) {
Type fieldType = Types.makeInferred(expressionType);
Elements.setType(element, fieldType);
}
@@ -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();