[FIR] Substitute copied type parameters in fake override properties
This commit is contained in:
+61
-16
@@ -352,16 +352,9 @@ class FirClassSubstitutionScope(
|
|||||||
val copiedParameterTypes = baseFunction.valueParameters.map {
|
val copiedParameterTypes = baseFunction.valueParameters.map {
|
||||||
substitutor.substituteOrNull(it.returnTypeRef.coneType)
|
substitutor.substituteOrNull(it.returnTypeRef.coneType)
|
||||||
}
|
}
|
||||||
val copiedReceiverType = newReceiverType?.let {
|
val (copiedReceiverType, copiedReturnType) = substituteReceiverAndReturnType(
|
||||||
substitutor.substituteOrNull(it)
|
baseFunction as FirCallableMemberDeclaration<*>, newReceiverType, newReturnType, substitutor
|
||||||
} ?: baseFunction.receiverTypeRef?.let {
|
)
|
||||||
substitutor.substituteOrNull(it.coneType)
|
|
||||||
}
|
|
||||||
val copiedReturnType = newReturnType?.let {
|
|
||||||
substitutor.substituteOrNull(it)
|
|
||||||
} ?: baseFunction.returnTypeRef.let {
|
|
||||||
substitutor.substituteOrNull(it.coneType)
|
|
||||||
}
|
|
||||||
configureAnnotationsAndSignature(session, baseFunction, copiedParameterTypes, copiedReceiverType, copiedReturnType)
|
configureAnnotationsAndSignature(session, baseFunction, copiedParameterTypes, copiedReceiverType, copiedReturnType)
|
||||||
copiedTypeParameters
|
copiedTypeParameters
|
||||||
}
|
}
|
||||||
@@ -421,22 +414,74 @@ class FirClassSubstitutionScope(
|
|||||||
source = baseProperty.source
|
source = baseProperty.source
|
||||||
this.session = session
|
this.session = session
|
||||||
origin = FirDeclarationOrigin.FakeOverride
|
origin = FirDeclarationOrigin.FakeOverride
|
||||||
returnTypeRef = baseProperty.returnTypeRef.withReplacedReturnType(newReturnType)
|
|
||||||
receiverTypeRef = baseProperty.receiverTypeRef?.withReplacedConeType(newReceiverType)
|
|
||||||
name = baseProperty.name
|
name = baseProperty.name
|
||||||
isVar = baseProperty.isVar
|
isVar = baseProperty.isVar
|
||||||
this.symbol = symbol
|
this.symbol = symbol
|
||||||
isLocal = false
|
isLocal = false
|
||||||
status = baseProperty.status.withExpect(isExpect)
|
status = baseProperty.status.withExpect(isExpect)
|
||||||
resolvePhase = baseProperty.resolvePhase
|
resolvePhase = baseProperty.resolvePhase
|
||||||
annotations += baseProperty.annotations
|
typeParameters += configureAnnotationsTypeParametersAndSignature(baseProperty, newTypeParameters, newReceiverType, newReturnType)
|
||||||
if (newTypeParameters != null) {
|
|
||||||
typeParameters += newTypeParameters
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return symbol
|
return symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun FirPropertyBuilder.configureAnnotationsTypeParametersAndSignature(
|
||||||
|
baseProperty: FirProperty,
|
||||||
|
newTypeParameters: List<FirTypeParameter>?,
|
||||||
|
newReceiverType: ConeKotlinType? = null,
|
||||||
|
newReturnType: ConeKotlinType? = null
|
||||||
|
): List<FirTypeParameter> {
|
||||||
|
return when {
|
||||||
|
baseProperty.typeParameters.isEmpty() -> {
|
||||||
|
configureAnnotationsAndSignature(baseProperty, newReceiverType, newReturnType)
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
newTypeParameters == null -> {
|
||||||
|
val (copiedTypeParameters, substitutor) = createNewTypeParametersAndSubstitutor(
|
||||||
|
baseProperty, ConeSubstitutor.Empty
|
||||||
|
)
|
||||||
|
val (copiedReceiverType, copiedReturnType) = substituteReceiverAndReturnType(
|
||||||
|
baseProperty, newReceiverType, newReturnType, substitutor
|
||||||
|
)
|
||||||
|
configureAnnotationsAndSignature(baseProperty, copiedReceiverType, copiedReturnType)
|
||||||
|
copiedTypeParameters.filterIsInstance<FirTypeParameter>()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
configureAnnotationsAndSignature(baseProperty, newReceiverType, newReturnType)
|
||||||
|
newTypeParameters
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun substituteReceiverAndReturnType(
|
||||||
|
baseCallable: FirCallableMemberDeclaration<*>,
|
||||||
|
newReceiverType: ConeKotlinType?,
|
||||||
|
newReturnType: ConeKotlinType?,
|
||||||
|
substitutor: ConeSubstitutor
|
||||||
|
): Pair<ConeKotlinType?, ConeKotlinType?> {
|
||||||
|
val copiedReceiverType = newReceiverType?.let {
|
||||||
|
substitutor.substituteOrNull(it)
|
||||||
|
} ?: baseCallable.receiverTypeRef?.let {
|
||||||
|
substitutor.substituteOrNull(it.coneType)
|
||||||
|
}
|
||||||
|
val copiedReturnType = newReturnType?.let {
|
||||||
|
substitutor.substituteOrNull(it)
|
||||||
|
} ?: baseCallable.returnTypeRef.let {
|
||||||
|
substitutor.substituteOrNull(it.coneType)
|
||||||
|
}
|
||||||
|
return copiedReceiverType to copiedReturnType
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun FirPropertyBuilder.configureAnnotationsAndSignature(
|
||||||
|
baseProperty: FirProperty,
|
||||||
|
newReceiverType: ConeKotlinType? = null,
|
||||||
|
newReturnType: ConeKotlinType? = null
|
||||||
|
) {
|
||||||
|
annotations += baseProperty.annotations
|
||||||
|
returnTypeRef = baseProperty.returnTypeRef.withReplacedConeType(newReturnType)
|
||||||
|
receiverTypeRef = baseProperty.receiverTypeRef?.withReplacedConeType(newReceiverType)
|
||||||
|
}
|
||||||
|
|
||||||
fun createFakeOverrideField(
|
fun createFakeOverrideField(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
baseField: FirField,
|
baseField: FirField,
|
||||||
|
|||||||
@@ -124,10 +124,11 @@ FILE fqName:<root> fileName:/useImportedMember.kt
|
|||||||
RETURN type=kotlin.Nothing from='public final fun <get-g2> <T> (): T of <root>.C.<get-g2> declared in <root>.C'
|
RETURN type=kotlin.Nothing from='public final fun <get-g2> <T> (): T of <root>.C.<get-g2> declared in <root>.C'
|
||||||
GET_VAR '<this>: T of <root>.C.<get-g2> declared in <root>.C.<get-g2>' type=T of <root>.C.<get-g2> origin=null
|
GET_VAR '<this>: T of <root>.C.<get-g2> declared in <root>.C.<get-g2>' type=T of <root>.C.<get-g2> origin=null
|
||||||
PROPERTY FAKE_OVERRIDE name:fromClass visibility:public modality:FINAL [fake_override,val]
|
PROPERTY FAKE_OVERRIDE name:fromClass visibility:public modality:FINAL [fake_override,val]
|
||||||
FUN FAKE_OVERRIDE name:<get-fromClass> visibility:public modality:FINAL <> ($this:<root>.BaseClass) returnType:T of <root>.BaseClass.<get-fromClass> [fake_override]
|
FUN FAKE_OVERRIDE name:<get-fromClass> visibility:public modality:FINAL <T> ($this:<root>.BaseClass) returnType:T of <root>.C.<get-fromClass> [fake_override]
|
||||||
correspondingProperty: PROPERTY FAKE_OVERRIDE name:fromClass visibility:public modality:FINAL [fake_override,val]
|
correspondingProperty: PROPERTY FAKE_OVERRIDE name:fromClass visibility:public modality:FINAL [fake_override,val]
|
||||||
overridden:
|
overridden:
|
||||||
public final fun <get-fromClass> <T> (): T of <root>.BaseClass.<get-fromClass> declared in <root>.BaseClass
|
public final fun <get-fromClass> <T> (): T of <root>.BaseClass.<get-fromClass> declared in <root>.BaseClass
|
||||||
|
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
||||||
$this: VALUE_PARAMETER name:<this> type:<root>.BaseClass
|
$this: VALUE_PARAMETER name:<this> type:<root>.BaseClass
|
||||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||||
overridden:
|
overridden:
|
||||||
|
|||||||
Reference in New Issue
Block a user