[FIR] Add type parameter mapping for substituted properties

This commit is contained in:
Mikhail Glukhikh
2020-04-08 13:35:10 +03:00
parent fcdbffde3f
commit 4543367c37
2 changed files with 27 additions and 13 deletions
@@ -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<List<FirTypeParameter>, 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<ConeKotlinType>()
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<FirTypeParameter>? = 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
}
@@ -54,23 +54,26 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
VALUE_PARAMETER name:a index:0 type:E of <root>.Test1
VALUE_PARAMETER name:b index:1 type:B of <root>.Test1.foo
PROPERTY FAKE_OVERRIDE name:id visibility:public modality:ABSTRACT [fake_override,val]
FUN FAKE_OVERRIDE name:<get-id> visibility:public modality:ABSTRACT <> ($this:<root>.Test1<E of <root>.Test1>) returnType:kotlin.collections.Map<E of <root>.Test1, C of <root>.IBase.<get-id>>? [fake_override]
FUN FAKE_OVERRIDE name:<get-id> visibility:public modality:ABSTRACT <C> ($this:<root>.Test1<E of <root>.Test1>) returnType:kotlin.collections.Map<E of <root>.Test1, C of <root>.Test1.<get-id>>? [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:id visibility:public modality:ABSTRACT [fake_override,val]
overridden:
public abstract fun <get-id> <C> (): kotlin.collections.Map<A of <root>.IBase, C of <root>.IBase.<get-id>>? declared in <root>.IBase
TYPE_PARAMETER name:C index:0 variance: superTypes:[kotlin.Any?]
$this: VALUE_PARAMETER name:<this> type:<root>.Test1<E of <root>.Test1>
PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var]
FUN FAKE_OVERRIDE name:<get-x> visibility:public modality:ABSTRACT <> ($this:<root>.Test1<E of <root>.Test1>) returnType:D of <root>.IBase.<get-x>? [fake_override]
FUN FAKE_OVERRIDE name:<get-x> visibility:public modality:ABSTRACT <D> ($this:<root>.Test1<E of <root>.Test1>) returnType:D of <root>.Test1.<get-x>? [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var]
overridden:
public abstract fun <get-x> <D> (): D of <root>.IBase.<get-x>? declared in <root>.IBase
TYPE_PARAMETER name:D index:0 variance: superTypes:[kotlin.Any?]
$this: VALUE_PARAMETER name:<this> type:<root>.Test1<E of <root>.Test1>
FUN FAKE_OVERRIDE name:<set-x> visibility:public modality:ABSTRACT <> ($this:<root>.Test1<E of <root>.Test1>, <set-?>:D of <root>.IBase.<set-x>?) returnType:kotlin.Unit [fake_override]
FUN FAKE_OVERRIDE name:<set-x> visibility:public modality:ABSTRACT <D> ($this:<root>.Test1<E of <root>.Test1>, <set-?>:D of <root>.Test1.<set-x>?) returnType:kotlin.Unit [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var]
overridden:
public abstract fun <set-x> <D> (<set-?>: D of <root>.IBase.<set-x>?): kotlin.Unit declared in <root>.IBase
TYPE_PARAMETER name:D index:0 variance: superTypes:[kotlin.Any?]
$this: VALUE_PARAMETER name:<this> type:<root>.Test1<E of <root>.Test1>
VALUE_PARAMETER name:<set-?> index:0 type:D of <root>.IBase.<set-x>?
VALUE_PARAMETER name:<set-?> index:0 type:D of <root>.Test1.<set-x>?
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:<root> fileName:/delegatedGenericImplementation.kt
VALUE_PARAMETER name:a index:0 type:kotlin.String
VALUE_PARAMETER name:b index:1 type:B of <root>.Test2.foo
PROPERTY FAKE_OVERRIDE name:id visibility:public modality:ABSTRACT [fake_override,val]
FUN FAKE_OVERRIDE name:<get-id> visibility:public modality:ABSTRACT <> ($this:<root>.Test2) returnType:kotlin.collections.Map<kotlin.String, C of <root>.IBase.<get-id>>? [fake_override]
FUN FAKE_OVERRIDE name:<get-id> visibility:public modality:ABSTRACT <C> ($this:<root>.Test2) returnType:kotlin.collections.Map<kotlin.String, C of <root>.Test2.<get-id>>? [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:id visibility:public modality:ABSTRACT [fake_override,val]
overridden:
public abstract fun <get-id> <C> (): kotlin.collections.Map<A of <root>.IBase, C of <root>.IBase.<get-id>>? declared in <root>.IBase
TYPE_PARAMETER name:C index:0 variance: superTypes:[kotlin.Any?]
$this: VALUE_PARAMETER name:<this> type:<root>.Test2
PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var]
FUN FAKE_OVERRIDE name:<get-x> visibility:public modality:ABSTRACT <> ($this:<root>.Test2) returnType:D of <root>.IBase.<get-x>? [fake_override]
FUN FAKE_OVERRIDE name:<get-x> visibility:public modality:ABSTRACT <D> ($this:<root>.Test2) returnType:D of <root>.Test2.<get-x>? [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var]
overridden:
public abstract fun <get-x> <D> (): D of <root>.IBase.<get-x>? declared in <root>.IBase
TYPE_PARAMETER name:D index:0 variance: superTypes:[kotlin.Any?]
$this: VALUE_PARAMETER name:<this> type:<root>.Test2
FUN FAKE_OVERRIDE name:<set-x> visibility:public modality:ABSTRACT <> ($this:<root>.Test2, <set-?>:D of <root>.IBase.<set-x>?) returnType:kotlin.Unit [fake_override]
FUN FAKE_OVERRIDE name:<set-x> visibility:public modality:ABSTRACT <D> ($this:<root>.Test2, <set-?>:D of <root>.Test2.<set-x>?) returnType:kotlin.Unit [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:x visibility:public modality:ABSTRACT [fake_override,var]
overridden:
public abstract fun <set-x> <D> (<set-?>: D of <root>.IBase.<set-x>?): kotlin.Unit declared in <root>.IBase
TYPE_PARAMETER name:D index:0 variance: superTypes:[kotlin.Any?]
$this: VALUE_PARAMETER name:<this> type:<root>.Test2
VALUE_PARAMETER name:<set-?> index:0 type:D of <root>.IBase.<set-x>?
VALUE_PARAMETER name:<set-?> index:0 type:D of <root>.Test2.<set-x>?
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