Minor. Simplify variable type resolution

This commit is contained in:
Denis Zharkov
2016-11-10 14:07:10 +03:00
parent e21ecbe702
commit 96fa04569a
@@ -54,38 +54,32 @@ class VariableTypeAndInitializerResolver(
): KotlinType { ): KotlinType {
val propertyTypeRef = variable.typeReference val propertyTypeRef = variable.typeReference
val hasDelegate = variable is KtProperty && variable.hasDelegateExpression()
return when { return when {
propertyTypeRef != null -> typeResolver.resolveType(scopeForInitializer, propertyTypeRef, trace, true) propertyTypeRef != null -> typeResolver.resolveType(scopeForInitializer, propertyTypeRef, trace, true)
!variable.hasInitializer() -> {
if (hasDelegate && variableDescriptor is VariableDescriptorWithAccessors) { !variable.hasInitializer() && variable is KtProperty && variableDescriptor is VariableDescriptorWithAccessors &&
val property = variable as KtProperty variable.hasDelegateExpression() ->
if (property.hasDelegateExpression()) { resolveDelegatedPropertyType(variable, variableDescriptor, scopeForInitializer, dataFlowInfo, trace)
return DeferredType.createRecursionIntolerant(
storageManager, variable.hasInitializer() -> when {
trace notLocal ->
) { DeferredType.createRecursionIntolerant(
resolveDelegatedPropertyType(property, variableDescriptor, scopeForInitializer, storageManager,
property.delegateExpression!!, dataFlowInfo, trace) trace
} ) {
PreliminaryDeclarationVisitor.createForDeclaration(variable, trace)
val initializerType = resolveInitializerType(scopeForInitializer, variable.initializer!!, dataFlowInfo, trace)
transformAnonymousTypeIfNeeded(variableDescriptor, variable, initializerType, trace)
} }
}
else -> resolveInitializerType(scopeForInitializer, variable.initializer!!, dataFlowInfo, trace)
}
else -> {
if (!notLocal) { if (!notLocal) {
trace.report(VARIABLE_WITH_NO_TYPE_NO_INITIALIZER.on(variable)) trace.report(VARIABLE_WITH_NO_TYPE_NO_INITIALIZER.on(variable))
} }
return ErrorUtils.createErrorType("No type, no body") ErrorUtils.createErrorType("No type, no body")
} }
notLocal -> {
DeferredType.createRecursionIntolerant(
storageManager,
trace
) {
PreliminaryDeclarationVisitor.createForDeclaration(variable, trace)
val initializerType = resolveInitializerType(scopeForInitializer, variable.initializer!!, dataFlowInfo, trace)
transformAnonymousTypeIfNeeded(variableDescriptor, variable, initializerType, trace)
}
}
else -> resolveInitializerType(scopeForInitializer, variable.initializer!!, dataFlowInfo, trace)
} }
} }
@@ -123,10 +117,10 @@ class VariableTypeAndInitializerResolver(
property: KtProperty, property: KtProperty,
variableDescriptor: VariableDescriptorWithAccessors, variableDescriptor: VariableDescriptorWithAccessors,
scopeForInitializer: LexicalScope, scopeForInitializer: LexicalScope,
delegateExpression: KtExpression,
dataFlowInfo: DataFlowInfo, dataFlowInfo: DataFlowInfo,
trace: BindingTrace trace: BindingTrace
): KotlinType { ) = DeferredType.createRecursionIntolerant(storageManager, trace) {
val delegateExpression = property.delegateExpression!!
val type = delegatedPropertyResolver.resolveDelegateExpression( val type = delegatedPropertyResolver.resolveDelegateExpression(
delegateExpression, property, variableDescriptor, scopeForInitializer, trace, dataFlowInfo) delegateExpression, property, variableDescriptor, scopeForInitializer, trace, dataFlowInfo)
@@ -134,10 +128,8 @@ class VariableTypeAndInitializerResolver(
val getterReturnType = delegatedPropertyResolver.getDelegatedPropertyGetMethodReturnType( val getterReturnType = delegatedPropertyResolver.getDelegatedPropertyGetMethodReturnType(
variableDescriptor, delegateExpression, type, trace, delegateFunctionsScope, dataFlowInfo variableDescriptor, delegateExpression, type, trace, delegateFunctionsScope, dataFlowInfo
) )
if (getterReturnType != null) {
return getterReturnType getterReturnType ?: ErrorUtils.createErrorType("Type from delegate")
}
return ErrorUtils.createErrorType("Type from delegate")
} }
private fun resolveInitializerType( private fun resolveInitializerType(