diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt index d64d3071dba..0bc22a5e8da 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt @@ -130,7 +130,7 @@ class FirClassSubstitutionScope( // Returns a list of type parameters, and a substitutor that should be used for all other types private fun createNewTypeParametersAndSubstitutor( - member: FirSimpleFunction + member: FirCallableMemberDeclaration<*> ): Pair, ConeSubstitutor> { if (member.typeParameters.isEmpty()) return Pair(member.typeParameters, substitutor) val newTypeParameters = member.typeParameters.map { originalParameter -> @@ -176,17 +176,21 @@ class FirClassSubstitutionScope( val member = original.fir if (skipPrivateMembers && member.visibility == Visibilities.PRIVATE) return original + val (newTypeParameters, newSubstitutor) = createNewTypeParametersAndSubstitutor(member) + val receiverType = member.receiverTypeRef?.coneTypeUnsafe() - val newReceiverType = receiverType?.substitute() + val newReceiverType = receiverType?.substitute(newSubstitutor) val returnType = typeCalculator.tryCalculateReturnType(member).type - val newReturnType = returnType.substitute() + val newReturnType = returnType.substitute(newSubstitutor) - if (newReceiverType == null && newReturnType == null) { + if (newReceiverType == null && + newReturnType == null && newTypeParameters === member.typeParameters + ) { return original } - return createFakeOverrideProperty(session, member, original, newReceiverType, newReturnType, derivedClassId) + return createFakeOverrideProperty(session, member, original, newReceiverType, newReturnType, newTypeParameters, derivedClassId) } private fun createFakeOverrideField(original: FirFieldSymbol): FirFieldSymbol { @@ -294,6 +298,7 @@ class FirClassSubstitutionScope( baseSymbol: FirPropertySymbol, newReceiverType: ConeKotlinType? = null, newReturnType: ConeKotlinType? = null, + newTypeParameters: List? = null, derivedClassId: ClassId? = null ): FirPropertySymbol { val symbol = FirPropertySymbol( @@ -312,6 +317,9 @@ class FirClassSubstitutionScope( status = baseProperty.status resolvePhase = baseProperty.resolvePhase annotations += baseProperty.annotations + if (newTypeParameters != null) { + typeParameters += newTypeParameters + } } return symbol } diff --git a/compiler/testData/ir/irText/classes/delegatedGenericImplementation.fir.txt b/compiler/testData/ir/irText/classes/delegatedGenericImplementation.fir.txt index 6753400c12f..e8ad17bf5ea 100644 --- a/compiler/testData/ir/irText/classes/delegatedGenericImplementation.fir.txt +++ b/compiler/testData/ir/irText/classes/delegatedGenericImplementation.fir.txt @@ -54,23 +54,26 @@ FILE fqName: fileName:/delegatedGenericImplementation.kt VALUE_PARAMETER name:a index:0 type:E of .Test1 VALUE_PARAMETER name:b index:1 type:B of .Test1.foo PROPERTY FAKE_OVERRIDE name:id visibility:public modality:ABSTRACT [fake_override,val] - FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.Test1.Test1>) returnType:kotlin.collections.Map.Test1, C of .IBase.>? [fake_override] + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT ($this:.Test1.Test1>) returnType:kotlin.collections.Map.Test1, C of .Test1.>? [fake_override] correspondingProperty: PROPERTY FAKE_OVERRIDE name:id visibility:public modality:ABSTRACT [fake_override,val] overridden: public abstract fun (): kotlin.collections.Map.IBase, C of .IBase.>? declared in .IBase + TYPE_PARAMETER name:C index:0 variance: superTypes:[kotlin.Any?] $this: VALUE_PARAMETER name: type:.Test1.Test1> PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var] - FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.Test1.Test1>) returnType:D of .IBase.? [fake_override] + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT ($this:.Test1.Test1>) returnType:D of .Test1.? [fake_override] correspondingProperty: PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var] overridden: public abstract fun (): D of .IBase.? declared in .IBase + TYPE_PARAMETER name:D index:0 variance: superTypes:[kotlin.Any?] $this: VALUE_PARAMETER name: type:.Test1.Test1> - FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.Test1.Test1>, :D of .IBase.?) returnType:kotlin.Unit [fake_override] + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT ($this:.Test1.Test1>, :D of .Test1.?) returnType:kotlin.Unit [fake_override] correspondingProperty: PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var] overridden: public abstract fun (: D of .IBase.?): kotlin.Unit declared in .IBase + TYPE_PARAMETER name:D index:0 variance: superTypes:[kotlin.Any?] $this: VALUE_PARAMETER name: type:.Test1.Test1> - VALUE_PARAMETER name: index:0 type:D of .IBase.? + VALUE_PARAMETER name: index:0 type:D of .Test1.? FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any @@ -118,23 +121,26 @@ FILE fqName: fileName:/delegatedGenericImplementation.kt VALUE_PARAMETER name:a index:0 type:kotlin.String VALUE_PARAMETER name:b index:1 type:B of .Test2.foo PROPERTY FAKE_OVERRIDE name:id visibility:public modality:ABSTRACT [fake_override,val] - FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.Test2) returnType:kotlin.collections.Map.IBase.>? [fake_override] + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT ($this:.Test2) returnType:kotlin.collections.Map.Test2.>? [fake_override] correspondingProperty: PROPERTY FAKE_OVERRIDE name:id visibility:public modality:ABSTRACT [fake_override,val] overridden: public abstract fun (): kotlin.collections.Map.IBase, C of .IBase.>? declared in .IBase + TYPE_PARAMETER name:C index:0 variance: superTypes:[kotlin.Any?] $this: VALUE_PARAMETER name: type:.Test2 PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var] - FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.Test2) returnType:D of .IBase.? [fake_override] + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT ($this:.Test2) returnType:D of .Test2.? [fake_override] correspondingProperty: PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var] overridden: public abstract fun (): D of .IBase.? declared in .IBase + TYPE_PARAMETER name:D index:0 variance: superTypes:[kotlin.Any?] $this: VALUE_PARAMETER name: type:.Test2 - FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT <> ($this:.Test2, :D of .IBase.?) returnType:kotlin.Unit [fake_override] + FUN FAKE_OVERRIDE name: visibility:public modality:ABSTRACT ($this:.Test2, :D of .Test2.?) returnType:kotlin.Unit [fake_override] correspondingProperty: PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var] overridden: public abstract fun (: D of .IBase.?): kotlin.Unit declared in .IBase + TYPE_PARAMETER name:D index:0 variance: superTypes:[kotlin.Any?] $this: VALUE_PARAMETER name: type:.Test2 - VALUE_PARAMETER name: index:0 type:D of .IBase.? + VALUE_PARAMETER name: index:0 type:D of .Test2.? FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any