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:
committed by
Space Team
parent
a2cefbc6be
commit
8cee2c36d3
+14
-18
@@ -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.buildAnonymousFunctionCopy
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildContextReceiver
|
import org.jetbrains.kotlin.fir.declarations.builder.buildContextReceiver
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
|
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.FirDefaultPropertyAccessor
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyBackingField
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyBackingField
|
||||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
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.ConeSimpleDiagnostic
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
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.FirStatusResolver
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.contracts.runContractResolveForFunction
|
import org.jetbrains.kotlin.fir.resolve.transformers.contracts.runContractResolveForFunction
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.transformVarargTypeToArrayType
|
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.symbols.impl.FirValueParameterSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
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.types.impl.FirImplicitTypeRefImplWithoutSource
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
open class FirDeclarationsResolveTransformer(
|
open class FirDeclarationsResolveTransformer(
|
||||||
transformer: FirAbstractBodyResolveTransformerDispatcher
|
transformer: FirAbstractBodyResolveTransformerDispatcher
|
||||||
@@ -310,7 +309,7 @@ open class FirDeclarationsResolveTransformer(
|
|||||||
|
|
||||||
// `isImplicitTypedProperty` means we haven't run setter resolution yet (see its second usage)
|
// `isImplicitTypedProperty` means we haven't run setter resolution yet (see its second usage)
|
||||||
if (isImplicitTypedProperty) {
|
if (isImplicitTypedProperty) {
|
||||||
property.resolveSetter(property.returnTypeRef, mayResolveSetterBody = true)
|
property.resolveSetter(mayResolveSetterBody = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataFlowAnalyzer.exitDelegateExpression(delegate)
|
dataFlowAnalyzer.exitDelegateExpression(delegate)
|
||||||
@@ -430,33 +429,30 @@ open class FirDeclarationsResolveTransformer(
|
|||||||
private fun FirProperty.transformAccessors(
|
private fun FirProperty.transformAccessors(
|
||||||
setterResolutionMode: SetterResolutionMode = SetterResolutionMode.FULLY_RESOLVE
|
setterResolutionMode: SetterResolutionMode = SetterResolutionMode.FULLY_RESOLVE
|
||||||
) {
|
) {
|
||||||
var enhancedTypeRef = returnTypeRef
|
|
||||||
if (bodyResolveState < FirPropertyBodyResolveState.INITIALIZER_AND_GETTER_RESOLVED) {
|
if (bodyResolveState < FirPropertyBodyResolveState.INITIALIZER_AND_GETTER_RESOLVED) {
|
||||||
getter?.let {
|
getter?.let {
|
||||||
transformAccessor(it, enhancedTypeRef, this)
|
transformAccessor(it, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (returnTypeRef is FirImplicitTypeRef) {
|
if (returnTypeRef is FirImplicitTypeRef) {
|
||||||
storeVariableReturnType(this)
|
storeVariableReturnType(this) // Here, we expect `this.returnTypeRef` is updated from the getter's return type
|
||||||
enhancedTypeRef = returnTypeRef
|
|
||||||
// We need update type of getter for case when its type was approximated
|
// 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) {
|
if (setterResolutionMode != SetterResolutionMode.SKIP) {
|
||||||
resolveSetter(enhancedTypeRef, mayResolveSetterBody = setterResolutionMode == SetterResolutionMode.FULLY_RESOLVE)
|
resolveSetter(mayResolveSetterBody = setterResolutionMode == SetterResolutionMode.FULLY_RESOLVE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirProperty.resolveSetter(
|
private fun FirProperty.resolveSetter(
|
||||||
enhancedTypeRef: FirTypeRef,
|
|
||||||
mayResolveSetterBody: Boolean,
|
mayResolveSetterBody: Boolean,
|
||||||
) {
|
) {
|
||||||
setter?.let {
|
setter?.let {
|
||||||
it.transformTypeWithPropertyType(enhancedTypeRef)
|
it.transformTypeWithPropertyType(returnTypeRef)
|
||||||
|
|
||||||
if (mayResolveSetterBody) {
|
if (mayResolveSetterBody) {
|
||||||
transformAccessor(it, enhancedTypeRef, this)
|
transformAccessor(it, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -482,16 +478,16 @@ open class FirDeclarationsResolveTransformer(
|
|||||||
|
|
||||||
private fun transformAccessor(
|
private fun transformAccessor(
|
||||||
accessor: FirPropertyAccessor,
|
accessor: FirPropertyAccessor,
|
||||||
enhancedTypeRef: FirTypeRef,
|
|
||||||
owner: FirProperty
|
owner: FirProperty
|
||||||
): Unit = whileAnalysing(session, accessor) {
|
): Unit = whileAnalysing(session, accessor) {
|
||||||
context.withPropertyAccessor(owner, accessor, components) {
|
context.withPropertyAccessor(owner, accessor, components) {
|
||||||
|
val propertyTypeRef = owner.returnTypeRef
|
||||||
if (accessor is FirDefaultPropertyAccessor || accessor.body == null) {
|
if (accessor is FirDefaultPropertyAccessor || accessor.body == null) {
|
||||||
transformFunction(accessor, withExpectedType(enhancedTypeRef))
|
transformFunction(accessor, withExpectedType(propertyTypeRef))
|
||||||
} else {
|
} else {
|
||||||
val returnTypeRef = accessor.returnTypeRef
|
val returnTypeRef = accessor.returnTypeRef
|
||||||
val expectedReturnTypeRef = if (enhancedTypeRef is FirResolvedTypeRef && returnTypeRef !is FirResolvedTypeRef) {
|
val expectedReturnTypeRef = if (propertyTypeRef is FirResolvedTypeRef && returnTypeRef !is FirResolvedTypeRef) {
|
||||||
enhancedTypeRef
|
propertyTypeRef
|
||||||
} else {
|
} else {
|
||||||
returnTypeRef
|
returnTypeRef
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user