Fix for KT-12891: Allow to omit type in local delegated property declaration

#KT-12891 Fixed
This commit is contained in:
Michael Bogdanov
2016-07-05 17:18:46 +03:00
parent 191dfa1f2b
commit 6b8e8cee17
7 changed files with 80 additions and 6 deletions
@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
import org.jetbrains.kotlin.descriptors.impl.VariableDescriptorWithInitializerImpl
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.Errors.VARIABLE_WITH_NO_TYPE_NO_INITIALIZER
@@ -62,7 +62,7 @@ class VariableTypeResolver(
return type
}
!variable.hasInitializer() -> {
if (hasDelegate && variableDescriptor is PropertyDescriptor) {
if (hasDelegate && variableDescriptor is VariableDescriptorWithAccessors) {
val property = variable as KtProperty
if (property.hasDelegateExpression()) {
return DeferredType.createRecursionIntolerant(
@@ -131,18 +131,18 @@ class VariableTypeResolver(
private fun resolveDelegatedPropertyType(
property: KtProperty,
propertyDescriptor: PropertyDescriptor,
variableDescriptor: VariableDescriptorWithAccessors,
scopeForInitializer: LexicalScope,
delegateExpression: KtExpression,
dataFlowInfo: DataFlowInfo,
trace: BindingTrace
): KotlinType {
val type = delegatedPropertyResolver.resolveDelegateExpression(
delegateExpression, property, propertyDescriptor, scopeForInitializer, trace, dataFlowInfo)
delegateExpression, property, variableDescriptor, scopeForInitializer, trace, dataFlowInfo)
val delegateFunctionsScope = ScopeUtils.makeScopeForDelegateConventionFunctions(scopeForInitializer, propertyDescriptor)
val delegateFunctionsScope = ScopeUtils.makeScopeForDelegateConventionFunctions(scopeForInitializer, variableDescriptor)
val getterReturnType = delegatedPropertyResolver.getDelegatedPropertyGetMethodReturnType(
propertyDescriptor, delegateExpression, type, trace, delegateFunctionsScope, dataFlowInfo
variableDescriptor, delegateExpression, type, trace, delegateFunctionsScope, dataFlowInfo
)
if (getterReturnType != null) {
return getterReturnType