[FIR] Substitute copied type parameters in fake override functions
This commit is contained in:
+30
-13
@@ -258,12 +258,18 @@ class FirClassSubstitutionScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun FirFunctionBuilder.configureAnnotationsAndParameters(
|
private fun FirFunctionBuilder.configureAnnotationsAndSignature(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
baseFunction: FirFunction<*>,
|
baseFunction: FirFunction<*>,
|
||||||
newParameterTypes: List<ConeKotlinType?>?
|
newParameterTypes: List<ConeKotlinType?>?,
|
||||||
|
newReceiverType: ConeKotlinType? = null,
|
||||||
|
newReturnType: ConeKotlinType? = null
|
||||||
) {
|
) {
|
||||||
annotations += baseFunction.annotations
|
annotations += baseFunction.annotations
|
||||||
|
returnTypeRef = baseFunction.returnTypeRef.withReplacedConeType(newReturnType)
|
||||||
|
if (this is FirSimpleFunctionBuilder) {
|
||||||
|
receiverTypeRef = baseFunction.receiverTypeRef?.withReplacedConeType(newReceiverType)
|
||||||
|
}
|
||||||
valueParameters += baseFunction.valueParameters.zip(
|
valueParameters += baseFunction.valueParameters.zip(
|
||||||
newParameterTypes ?: List(baseFunction.valueParameters.size) { null }
|
newParameterTypes ?: List(baseFunction.valueParameters.size) { null }
|
||||||
) { valueParameter, newType ->
|
) { valueParameter, newType ->
|
||||||
@@ -283,15 +289,17 @@ class FirClassSubstitutionScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirFunctionBuilder.configureAnnotationsAndAllParameters(
|
private fun FirFunctionBuilder.configureAnnotationsTypeParametersAndSignature(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
baseFunction: FirFunction<*>,
|
baseFunction: FirFunction<*>,
|
||||||
newParameterTypes: List<ConeKotlinType?>?,
|
newParameterTypes: List<ConeKotlinType?>?,
|
||||||
newTypeParameters: List<FirTypeParameterRef>?
|
newTypeParameters: List<FirTypeParameterRef>?,
|
||||||
|
newReceiverType: ConeKotlinType? = null,
|
||||||
|
newReturnType: ConeKotlinType? = null
|
||||||
): List<FirTypeParameterRef> {
|
): List<FirTypeParameterRef> {
|
||||||
return when {
|
return when {
|
||||||
baseFunction.typeParameters.isEmpty() -> {
|
baseFunction.typeParameters.isEmpty() -> {
|
||||||
configureAnnotationsAndParameters(session, baseFunction, newParameterTypes)
|
configureAnnotationsAndSignature(session, baseFunction, newParameterTypes, newReceiverType, newReturnType)
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
newTypeParameters == null -> {
|
newTypeParameters == null -> {
|
||||||
@@ -301,11 +309,21 @@ class FirClassSubstitutionScope(
|
|||||||
val copiedParameterTypes = baseFunction.valueParameters.map {
|
val copiedParameterTypes = baseFunction.valueParameters.map {
|
||||||
substitutor.substituteOrNull(it.returnTypeRef.coneType)
|
substitutor.substituteOrNull(it.returnTypeRef.coneType)
|
||||||
}
|
}
|
||||||
configureAnnotationsAndParameters(session, baseFunction, copiedParameterTypes)
|
val copiedReceiverType = newReceiverType?.let {
|
||||||
|
substitutor.substituteOrNull(it)
|
||||||
|
} ?: 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)
|
||||||
copiedTypeParameters
|
copiedTypeParameters
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
configureAnnotationsAndParameters(session, baseFunction, newParameterTypes)
|
configureAnnotationsAndSignature(session, baseFunction, newParameterTypes, newReceiverType, newReturnType)
|
||||||
newTypeParameters
|
newTypeParameters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,15 +355,13 @@ class FirClassSubstitutionScope(
|
|||||||
source = baseFunction.source
|
source = baseFunction.source
|
||||||
this.session = session
|
this.session = session
|
||||||
origin = FirDeclarationOrigin.FakeOverride
|
origin = FirDeclarationOrigin.FakeOverride
|
||||||
returnTypeRef = baseFunction.returnTypeRef.withReplacedReturnType(newReturnType)
|
|
||||||
receiverTypeRef = baseFunction.receiverTypeRef?.withReplacedConeType(newReceiverType)
|
|
||||||
name = baseFunction.name
|
name = baseFunction.name
|
||||||
status = baseFunction.status.withExpect(isExpect)
|
status = baseFunction.status.withExpect(isExpect)
|
||||||
symbol = fakeOverrideSymbol
|
symbol = fakeOverrideSymbol
|
||||||
resolvePhase = baseFunction.resolvePhase
|
resolvePhase = baseFunction.resolvePhase
|
||||||
|
|
||||||
typeParameters += configureAnnotationsAndAllParameters(
|
typeParameters += configureAnnotationsTypeParametersAndSignature(
|
||||||
session, baseFunction, newParameterTypes, newTypeParameters
|
session, baseFunction, newParameterTypes, newTypeParameters, newReceiverType, newReturnType
|
||||||
).filterIsInstance<FirTypeParameter>()
|
).filterIsInstance<FirTypeParameter>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -465,13 +481,14 @@ class FirClassSubstitutionScope(
|
|||||||
source = baseConstructor.source
|
source = baseConstructor.source
|
||||||
this.session = session
|
this.session = session
|
||||||
origin = FirDeclarationOrigin.FakeOverride
|
origin = FirDeclarationOrigin.FakeOverride
|
||||||
returnTypeRef = baseConstructor.returnTypeRef.withReplacedReturnType(newReturnType)
|
|
||||||
receiverTypeRef = baseConstructor.receiverTypeRef?.withReplacedConeType(null)
|
receiverTypeRef = baseConstructor.receiverTypeRef?.withReplacedConeType(null)
|
||||||
status = baseConstructor.status.withExpect(isExpect)
|
status = baseConstructor.status.withExpect(isExpect)
|
||||||
symbol = fakeOverrideSymbol
|
symbol = fakeOverrideSymbol
|
||||||
resolvePhase = baseConstructor.resolvePhase
|
resolvePhase = baseConstructor.resolvePhase
|
||||||
|
|
||||||
typeParameters += configureAnnotationsAndAllParameters(session, baseConstructor, newParameterTypes, newTypeParameters)
|
typeParameters += configureAnnotationsTypeParametersAndSignature(
|
||||||
|
session, baseConstructor, newParameterTypes, newTypeParameters, null, newReturnType
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ FILE fqName:<root> fileName:/FirBuilder.kt
|
|||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.BaseConverter'
|
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.BaseConverter'
|
||||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:DeclarationsConverter modality:FINAL visibility:public superTypes:[<root>.BaseConverter]'
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:DeclarationsConverter modality:FINAL visibility:public superTypes:[<root>.BaseConverter]'
|
||||||
FUN FAKE_OVERRIDE name:withCapturedTypeParameters visibility:public modality:FINAL <T> ($this:<root>.BaseConverter, block:kotlin.Function0<T of <root>.DeclarationsConverter.withCapturedTypeParameters>) returnType:T of <root>.BaseConverter.withCapturedTypeParameters [inline,fake_override]
|
FUN FAKE_OVERRIDE name:withCapturedTypeParameters visibility:public modality:FINAL <T> ($this:<root>.BaseConverter, block:kotlin.Function0<T of <root>.DeclarationsConverter.withCapturedTypeParameters>) returnType:T of <root>.DeclarationsConverter.withCapturedTypeParameters [inline,fake_override]
|
||||||
overridden:
|
overridden:
|
||||||
public final fun withCapturedTypeParameters <T> (block: kotlin.Function0<T of <root>.BaseFirBuilder.withCapturedTypeParameters>): T of <root>.BaseFirBuilder.withCapturedTypeParameters [inline] declared in <root>.BaseFirBuilder
|
public final fun withCapturedTypeParameters <T> (block: kotlin.Function0<T of <root>.BaseFirBuilder.withCapturedTypeParameters>): T of <root>.BaseFirBuilder.withCapturedTypeParameters [inline] declared in <root>.BaseFirBuilder
|
||||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
||||||
|
|||||||
Reference in New Issue
Block a user