Type of local variable initializer is checked

This commit is contained in:
Andrey Breslav
2011-03-23 17:32:56 +03:00
parent a476377d35
commit 3e6915e709
2 changed files with 23 additions and 0 deletions
+1
View File
@@ -1,6 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="abreslav">
<words>
<w>accessor</w>
<w>inferrer</w>
<w>nullable</w>
<w>substitutor</w>
@@ -1092,7 +1092,29 @@ public class JetTypeInferrer {
@Override
public void visitProperty(JetProperty property) {
JetPropertyAccessor getter = property.getGetter();
if (getter != null) {
semanticServices.getErrorHandler().genericError(getter.getNode(), "Local variables are not allowed to have getters");
}
JetPropertyAccessor setter = property.getSetter();
if (setter != null) {
semanticServices.getErrorHandler().genericError(setter.getNode(), "Local variables are not allowed to have setters");
}
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePropertyDescriptor(scope.getContainingDeclaration(), scope, property);
JetExpression initializer = property.getInitializer();
if (property.getPropertyTypeRef() != null && initializer != null) {
JetType initializerType = getType(scope, initializer, false);
JetType outType = propertyDescriptor.getOutType();
if (outType != null &&
initializerType != null &&
!semanticServices.getTypeChecker().isConvertibleTo(initializerType, outType)) {
semanticServices.getErrorHandler().typeMismatch(initializer, outType, initializerType);
}
}
scope.addPropertyDescriptor(propertyDescriptor);
trace.recordDeclarationResolution(property, propertyDescriptor);
}