Initializer checking fixed

This commit is contained in:
Andrey Breslav
2011-09-02 16:59:11 +04:00
parent 3680d97107
commit 3aa9b9c3ef
@@ -863,19 +863,12 @@ public class TopDownAnalyzer {
JetTypeInferrer.Services typeInferrer = semanticServices.getTypeInferrerServices(traceForConstructors, flowInformationProvider); JetTypeInferrer.Services typeInferrer = semanticServices.getTypeInferrerServices(traceForConstructors, flowInformationProvider);
JetType type = typeInferrer.getType(getPropertyDeclarationInnerScope(scope, propertyDescriptor), initializer, NO_EXPECTED_TYPE); JetType type = typeInferrer.getType(getPropertyDeclarationInnerScope(scope, propertyDescriptor), initializer, NO_EXPECTED_TYPE);
JetType expectedType; JetType expectedType = propertyDescriptor.getInType();
PropertySetterDescriptor setter = propertyDescriptor.getSetter(); if (expectedType == null) {
if (setter != null) { expectedType = propertyDescriptor.getOutType();
expectedType = setter.getReturnType();
}
else {
expectedType = propertyDescriptor.getInType();
if (expectedType == null) {
expectedType = propertyDescriptor.getOutType();
}
} }
if (type != null && expectedType != null if (type != null && expectedType != null
&& !semanticServices.getTypeChecker().isConvertibleTo(type, expectedType)) { && !semanticServices.getTypeChecker().isSubtypeOf(type, expectedType)) {
trace.getErrorHandler().typeMismatch(initializer, expectedType, type); trace.getErrorHandler().typeMismatch(initializer, expectedType, type);
} }
} }
@@ -888,7 +881,7 @@ public class TopDownAnalyzer {
JetScope declaringScope = declaringScopes.get(declaration); JetScope declaringScope = declaringScopes.get(declaration);
assert declaringScope != null; assert declaringScope != null;
resolveFunctionBody(traceForMembers, (JetNamedFunction) declaration, (FunctionDescriptorImpl) descriptor, declaringScope); resolveFunctionBody(traceForMembers, (JetNamedFunction) declaration, descriptor, declaringScope);
assert descriptor.getReturnType() != null; assert descriptor.getReturnType() != null;
} }