K2: Get rid of enhancedTypeRef concept in property accessors

As it's always equal to the latest value at `property.returnTypeRef`
This commit is contained in:
Denis.Zharkov
2023-07-11 11:23:00 +02:00
committed by Space Team
parent a2cefbc6be
commit 8cee2c36d3
@@ -16,11 +16,12 @@ import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.buildAnonymousFunctionCopy
import org.jetbrains.kotlin.fir.declarations.builder.buildContextReceiver
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyBackingField
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
import org.jetbrains.kotlin.fir.declarations.utils.*
import org.jetbrains.kotlin.fir.declarations.utils.hasExplicitBackingField
import org.jetbrains.kotlin.fir.declarations.utils.isInline
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.expressions.*
@@ -39,7 +40,6 @@ import org.jetbrains.kotlin.fir.resolve.transformers.FirCallCompletionResultsWri
import org.jetbrains.kotlin.fir.resolve.transformers.FirStatusResolver
import org.jetbrains.kotlin.fir.resolve.transformers.contracts.runContractResolveForFunction
import org.jetbrains.kotlin.fir.resolve.transformers.transformVarargTypeToArrayType
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
@@ -47,7 +47,6 @@ import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.transformSingle
import org.jetbrains.kotlin.name.Name
open class FirDeclarationsResolveTransformer(
transformer: FirAbstractBodyResolveTransformerDispatcher
@@ -310,7 +309,7 @@ open class FirDeclarationsResolveTransformer(
// `isImplicitTypedProperty` means we haven't run setter resolution yet (see its second usage)
if (isImplicitTypedProperty) {
property.resolveSetter(property.returnTypeRef, mayResolveSetterBody = true)
property.resolveSetter(mayResolveSetterBody = true)
}
dataFlowAnalyzer.exitDelegateExpression(delegate)
@@ -430,33 +429,30 @@ open class FirDeclarationsResolveTransformer(
private fun FirProperty.transformAccessors(
setterResolutionMode: SetterResolutionMode = SetterResolutionMode.FULLY_RESOLVE
) {
var enhancedTypeRef = returnTypeRef
if (bodyResolveState < FirPropertyBodyResolveState.INITIALIZER_AND_GETTER_RESOLVED) {
getter?.let {
transformAccessor(it, enhancedTypeRef, this)
transformAccessor(it, this)
}
}
if (returnTypeRef is FirImplicitTypeRef) {
storeVariableReturnType(this)
enhancedTypeRef = returnTypeRef
storeVariableReturnType(this) // Here, we expect `this.returnTypeRef` is updated from the getter's return type
// We need update type of getter for case when its type was approximated
getter?.transformTypeWithPropertyType(enhancedTypeRef, forceUpdateForNonImplicitTypes = true)
getter?.transformTypeWithPropertyType(returnTypeRef, forceUpdateForNonImplicitTypes = true)
}
if (setterResolutionMode != SetterResolutionMode.SKIP) {
resolveSetter(enhancedTypeRef, mayResolveSetterBody = setterResolutionMode == SetterResolutionMode.FULLY_RESOLVE)
resolveSetter(mayResolveSetterBody = setterResolutionMode == SetterResolutionMode.FULLY_RESOLVE)
}
}
private fun FirProperty.resolveSetter(
enhancedTypeRef: FirTypeRef,
mayResolveSetterBody: Boolean,
) {
setter?.let {
it.transformTypeWithPropertyType(enhancedTypeRef)
it.transformTypeWithPropertyType(returnTypeRef)
if (mayResolveSetterBody) {
transformAccessor(it, enhancedTypeRef, this)
transformAccessor(it, this)
}
}
}
@@ -482,16 +478,16 @@ open class FirDeclarationsResolveTransformer(
private fun transformAccessor(
accessor: FirPropertyAccessor,
enhancedTypeRef: FirTypeRef,
owner: FirProperty
): Unit = whileAnalysing(session, accessor) {
context.withPropertyAccessor(owner, accessor, components) {
val propertyTypeRef = owner.returnTypeRef
if (accessor is FirDefaultPropertyAccessor || accessor.body == null) {
transformFunction(accessor, withExpectedType(enhancedTypeRef))
transformFunction(accessor, withExpectedType(propertyTypeRef))
} else {
val returnTypeRef = accessor.returnTypeRef
val expectedReturnTypeRef = if (enhancedTypeRef is FirResolvedTypeRef && returnTypeRef !is FirResolvedTypeRef) {
enhancedTypeRef
val expectedReturnTypeRef = if (propertyTypeRef is FirResolvedTypeRef && returnTypeRef !is FirResolvedTypeRef) {
propertyTypeRef
} else {
returnTypeRef
}