[FIR] introduce FirReceiverParameter

^KT-54417
This commit is contained in:
Dmitrii Gridin
2022-10-12 16:26:28 +02:00
committed by Space Team
parent e6801abce8
commit be7d282974
142 changed files with 821 additions and 580 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -281,7 +281,7 @@ class FirClassSubstitutionScope(
forceTypeParametersRecreation = dispatchReceiverTypeForSubstitutedMembers.lookupTag != member.dispatchReceiverClassLookupTagOrNull()
)
val receiverType = member.receiverTypeRef?.coneType
val receiverType = member.receiverParameter?.type?.coneType
val newReceiverType = receiverType?.substitute(substitutor)
val newDispatchReceiverType = dispatchReceiverTypeForSubstitutedMembers.substitute(substitutor)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -147,9 +147,15 @@ object FirFakeOverrideGenerator {
// TODO: consider using here some light-weight functions instead of pseudo-real FirMemberFunctionImpl
// As second alternative, we can invent some light-weight kind of FirRegularClass
return buildConstructor {
annotations += baseConstructor.annotations
moduleData = session.moduleData
this.origin = origin
receiverTypeRef = baseConstructor.receiverTypeRef?.withReplacedConeType(null)
receiverParameter = baseConstructor.receiverParameter?.let { receiverParameter ->
buildReceiverParameterCopy(receiverParameter) {
type = receiverParameter.type.withReplacedConeType(null)
}
}
status = baseConstructor.status.copy(isExpect = isExpect)
symbol = fakeOverrideSymbol
@@ -261,7 +267,11 @@ object FirFakeOverrideGenerator {
}
if (this is FirSimpleFunctionBuilder) {
receiverTypeRef = baseFunction.receiverTypeRef?.withReplacedConeType(newReceiverType)
receiverParameter = baseFunction.receiverParameter?.let { receiverParameter ->
buildReceiverParameterCopy(receiverParameter) {
type = receiverParameter.type.withReplacedConeType(newReceiverType)
}
}
}
valueParameters += baseFunction.valueParameters.zip(
newParameterTypes ?: List(baseFunction.valueParameters.size) { null }
@@ -408,7 +418,7 @@ object FirFakeOverrideGenerator {
): Triple<ConeKotlinType?, List<ConeKotlinType?>, Maybe<ConeKotlinType?>> {
val copiedReceiverType = newReceiverType?.let {
substitutor.substituteOrNull(it)
} ?: baseCallable.receiverTypeRef?.let {
} ?: baseCallable.receiverParameter?.type?.let {
substitutor.substituteOrNull(it.coneType)
}
@@ -444,13 +454,20 @@ object FirFakeOverrideGenerator {
val fakeOverrideSubstitution = fakeOverrideSubstitution ?: runIf(baseProperty.returnTypeRef is FirImplicitTypeRef) {
FakeOverrideSubstitution(ConeSubstitutor.Empty, baseProperty.symbol)
}
if (fakeOverrideSubstitution != null) {
returnTypeRef = buildImplicitTypeRef()
attributes.fakeOverrideSubstitution = fakeOverrideSubstitution
} else {
returnTypeRef = baseProperty.returnTypeRef.withReplacedReturnType(newReturnType)
}
receiverTypeRef = baseProperty.receiverTypeRef?.withReplacedConeType(newReceiverType)
receiverParameter = baseProperty.receiverParameter?.let { receiverParameter ->
buildReceiverParameterCopy(receiverParameter) {
type = receiverParameter.type.withReplacedConeType(newReceiverType)
}
}
contextReceivers += baseProperty.contextReceivers.zip(
newContextReceiverTypes ?: List(baseProperty.contextReceivers.size) { null }
) { contextReceiver, newType ->
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -130,7 +130,12 @@ class FirStandardOverrideChecker(private val session: FirSession) : FirAbstractO
overrideCandidate.lazyResolveToPhase(FirResolvePhase.TYPES)
baseDeclaration.lazyResolveToPhase(FirResolvePhase.TYPES)
if (!isEqualReceiverTypes(overrideCandidate.receiverTypeRef, baseDeclaration.receiverTypeRef, substitutor)) return false
if (!isEqualReceiverTypes(
overrideCandidate.receiverParameter?.type,
baseDeclaration.receiverParameter?.type,
substitutor,
)
) return false
return overrideCandidate.valueParameters.zip(baseDeclaration.valueParameters).all { (memberParam, selfParam) ->
isEqualTypes(memberParam.returnTypeRef, selfParam.returnTypeRef, substitutor)
@@ -147,6 +152,6 @@ class FirStandardOverrideChecker(private val session: FirSession) : FirAbstractO
val substitutor = buildTypeParametersSubstitutorIfCompatible(overrideCandidate, baseDeclaration) ?: return false
overrideCandidate.lazyResolveToPhase(FirResolvePhase.TYPES)
baseDeclaration.lazyResolveToPhase(FirResolvePhase.TYPES)
return isEqualReceiverTypes(overrideCandidate.receiverTypeRef, baseDeclaration.receiverTypeRef, substitutor)
return isEqualReceiverTypes(overrideCandidate.receiverParameter?.type, baseDeclaration.receiverParameter?.type, substitutor)
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -240,7 +240,7 @@ fun ConeKotlinType.valueParameterTypesIncludingReceiver(session: FirSession): Li
}
val FirAnonymousFunction.returnType: ConeKotlinType? get() = returnTypeRef.coneTypeSafe()
val FirAnonymousFunction.receiverType: ConeKotlinType? get() = receiverTypeRef?.coneTypeSafe()
val FirAnonymousFunction.receiverType: ConeKotlinType? get() = receiverParameter?.type?.coneTypeSafe()
fun ConeTypeContext.isTypeMismatchDueToNullability(
actualType: ConeKotlinType,