From 060864f7af1cb49a4957179f987c62ae1e937524 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 12 Jan 2016 13:02:54 +0300 Subject: [PATCH] Minor: prettify code after autoconversion --- .../kotlin/resolve/VariableTypeResolver.kt | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeResolver.kt index 2ffdd58f3b4..2112ebc599f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/VariableTypeResolver.kt @@ -55,8 +55,13 @@ class VariableTypeResolver( val propertyTypeRef = variable.typeReference val hasDelegate = variable is KtProperty && variable.hasDelegateExpression() - if (propertyTypeRef == null) { - if (!variable.hasInitializer()) { + when { + propertyTypeRef != null -> { + val type = typeResolver.resolveType(scopeForInitializer, propertyTypeRef, trace, true) + setConstantForVariableIfNeeded(variableDescriptor, scopeForInitializer, variable, dataFlowInfo, type, trace) + return type + } + !variable.hasInitializer() -> { if (hasDelegate && variableDescriptor is PropertyDescriptor) { val property = variable as KtProperty if (property.hasDelegateExpression()) { @@ -74,29 +79,22 @@ class VariableTypeResolver( } return ErrorUtils.createErrorType("No type, no body") } - else { - if (notLocal) { - return DeferredType.createRecursionIntolerant( - storageManager, - trace - ) { - PreliminaryDeclarationVisitor.createForDeclaration(variable, trace) - val initializerType = resolveInitializerType(scopeForInitializer, variable.initializer!!, dataFlowInfo, trace) - setConstantForVariableIfNeeded(variableDescriptor, scopeForInitializer, variable, dataFlowInfo, initializerType, trace) - transformAnonymousTypeIfNeeded(variableDescriptor, variable, initializerType, trace) - } - } - else { + notLocal -> { + return DeferredType.createRecursionIntolerant( + storageManager, + trace + ) { + PreliminaryDeclarationVisitor.createForDeclaration(variable, trace) val initializerType = resolveInitializerType(scopeForInitializer, variable.initializer!!, dataFlowInfo, trace) setConstantForVariableIfNeeded(variableDescriptor, scopeForInitializer, variable, dataFlowInfo, initializerType, trace) - return initializerType + transformAnonymousTypeIfNeeded(variableDescriptor, variable, initializerType, trace) } } - } - else { - val type = typeResolver.resolveType(scopeForInitializer, propertyTypeRef, trace, true) - setConstantForVariableIfNeeded(variableDescriptor, scopeForInitializer, variable, dataFlowInfo, type, trace) - return type + else -> { + val initializerType = resolveInitializerType(scopeForInitializer, variable.initializer!!, dataFlowInfo, trace) + setConstantForVariableIfNeeded(variableDescriptor, scopeForInitializer, variable, dataFlowInfo, initializerType, trace) + return initializerType + } } } @@ -142,12 +140,10 @@ class VariableTypeResolver( val type = delegatedPropertyResolver.resolveDelegateExpression( delegateExpression, property, propertyDescriptor, scopeForInitializer, trace, dataFlowInfo) - if (type != null) { - val delegateFunctionsScope = ScopeUtils.makeScopeForDelegateConventionFunctions(scopeForInitializer, propertyDescriptor) - val getterReturnType = delegatedPropertyResolver.getDelegatedPropertyGetMethodReturnType(propertyDescriptor, delegateExpression, type, trace, delegateFunctionsScope) - if (getterReturnType != null) { - return getterReturnType - } + val delegateFunctionsScope = ScopeUtils.makeScopeForDelegateConventionFunctions(scopeForInitializer, propertyDescriptor) + val getterReturnType = delegatedPropertyResolver.getDelegatedPropertyGetMethodReturnType(propertyDescriptor, delegateExpression, type, trace, delegateFunctionsScope) + if (getterReturnType != null) { + return getterReturnType } return ErrorUtils.createErrorType("Type from delegate") }