[FIR] FirReceiverParameter: rename type to typeRef

^KT-54417
This commit is contained in:
Dmitrii Gridin
2022-11-11 07:47:39 +01:00
committed by Space Team
parent 40c64c672d
commit 86422d0944
57 changed files with 110 additions and 108 deletions
@@ -679,7 +679,7 @@ private fun collectReferencedTypeParameters(declaration: FirCallableDeclaration)
}
override fun visitReceiverParameter(receiverParameter: FirReceiverParameter) {
receiverParameter.type.accept(this)
receiverParameter.typeRef.accept(this)
}
override fun visitResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef) {
@@ -31,7 +31,7 @@ internal class KtFirReceiverParameterSymbol(
override val token: KtLifetimeToken,
private val builder: KtSymbolByFirBuilder
) : KtReceiverParameterSymbol(), KtLifetimeOwner {
override val psi: PsiElement? by cached { firSymbol.fir.receiverParameter?.type?.findPsi(firSymbol.fir.moduleData.session) }
override val psi: PsiElement? by cached { firSymbol.fir.receiverParameter?.typeRef?.findPsi(firSymbol.fir.moduleData.session) }
init {
require(firSymbol.fir.receiverParameter != null) { "$firSymbol doesn't have an extension receiver." }
@@ -42,7 +42,7 @@ object KtDeclarationAndFirDeclarationEqualityChecker {
private fun receiverTypeMatch(psi: KtCallableDeclaration, fir: FirCallableDeclaration): Boolean {
if ((fir.receiverParameter != null) != (psi.receiverTypeReference != null)) return false
if (fir.receiverParameter != null && !isTheSameTypes(psi.receiverTypeReference!!, fir.receiverParameter!!.type, isVararg = false)) {
if (fir.receiverParameter != null && !isTheSameTypes(psi.receiverTypeReference!!, fir.receiverParameter!!.typeRef, isVararg = false)) {
return false
}
return true
@@ -223,7 +223,7 @@ object KtDeclarationAndFirDeclarationEqualityChecker {
@TestOnly
fun renderFir(firFunction: FirFunction): String = buildString {
appendLine("receiver: ${firFunction.receiverParameter?.type?.renderTypeAsKotlinType()}")
appendLine("receiver: ${firFunction.receiverParameter?.typeRef?.renderTypeAsKotlinType()}")
firFunction.valueParameters.forEach { parameter ->
appendLine("${parameter.name}: ${parameter.returnTypeRef.renderTypeAsKotlinType()}")
}
@@ -46,7 +46,7 @@ internal fun checkReturnTypeRefIsResolved(declaration: FirCallableDeclaration, a
}
internal fun checkReceiverTypeRefIsResolved(declaration: FirCallableDeclaration, acceptImplicitTypeRef: Boolean = false) {
val receiverTypeRef = declaration.receiverParameter?.type ?: return
val receiverTypeRef = declaration.receiverParameter?.typeRef ?: return
checkTypeRefIsResolved(receiverTypeRef, typeRefName = "receiver type", declaration, acceptImplicitTypeRef)
}
@@ -56,7 +56,7 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
}
}
if (function.receiverParameter?.type.isFunctionalTypeRef(session)) {
if (function.receiverParameter?.typeRef.isFunctionalTypeRef(session)) {
val effectDeclaration = function.contractDescription.getParameterCallsEffectDeclaration(-1)
if (effectDeclaration != null) functionalTypeEffects[function.symbol] = effectDeclaration
}
@@ -226,9 +226,9 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker() {
private fun FirFunction.getParameterType(symbol: FirBasedSymbol<*>, context: CheckerContext): ConeKotlinType? {
val typeRef = if (this.symbol == symbol) {
if (symbol is FirPropertyAccessorSymbol) {
context.containingProperty?.receiverParameter?.type
context.containingProperty?.receiverParameter?.typeRef
} else {
receiverParameter?.type
receiverParameter?.typeRef
}
} else {
valueParameters.find { it.symbol == symbol }?.returnTypeRef
@@ -147,7 +147,7 @@ interface FirDeclarationPresenter {
fun represent(it: FirVariable) = buildString {
append('[')
it.receiverParameter?.type?.let {
it.receiverParameter?.typeRef?.let {
appendRepresentation(it)
}
append(']')
@@ -172,7 +172,7 @@ interface FirDeclarationPresenter {
}
append('>')
append('[')
it.receiverParameter?.type?.let {
it.receiverParameter?.typeRef?.let {
appendRepresentation(it)
}
append(']')
@@ -74,7 +74,7 @@ object FirClassVarianceChecker : FirClassChecker() {
checkVarianceConflict(member.returnTypeRef, returnTypeVariance, context, reporter, returnSource)
val receiverTypeRef = member.receiverParameter?.type
val receiverTypeRef = member.receiverParameter?.typeRef
if (receiverTypeRef != null) {
checkVarianceConflict(receiverTypeRef, Variance.IN_VARIANCE, context, reporter)
}
@@ -142,7 +142,7 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
}
}
}
checkMemberReceiver(declaration.receiverParameter?.type, declaration as? FirCallableDeclaration, reporter, context)
checkMemberReceiver(declaration.receiverParameter?.typeRef, declaration as? FirCallableDeclaration, reporter, context)
}
private fun checkProperty(declaration: FirProperty, reporter: DiagnosticReporter, context: CheckerContext) {
@@ -172,7 +172,7 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
)
}
}
checkMemberReceiver(declaration.receiverParameter?.type, declaration, reporter, context)
checkMemberReceiver(declaration.receiverParameter?.typeRef, declaration, reporter, context)
}
private fun checkMemberReceiver(
@@ -209,7 +209,7 @@ private object OperatorFunctionChecks {
setOf(INC, DEC),
memberOrExtension,
Checks.full("receiver must be a supertype of the return type") { ctx, function ->
val receiver = function.dispatchReceiverType ?: function.receiverParameter?.type?.coneType ?: return@full false
val receiver = function.dispatchReceiverType ?: function.receiverParameter?.typeRef?.coneType ?: return@full false
function.returnTypeRef.coneType.isSubtypeOf(ctx.session.typeContext, receiver)
}
)
@@ -28,7 +28,7 @@ object FirPropertyTypeParametersChecker : FirPropertyChecker() {
}
}
}
declaration.receiverParameter?.type?.let { collectAllTypes(it.coneType) }
declaration.receiverParameter?.typeRef?.let { collectAllTypes(it.coneType) }
declaration.contextReceivers.forEach { collectAllTypes(it.typeRef.coneType) }
val usedNames = usedTypes.filterIsInstance<ConeTypeParameterType>().map { it.lookupTag.name }
@@ -69,7 +69,7 @@ object FirReservedUnderscoreDeclarationChecker : FirBasicDeclarationChecker() {
val returnOrReceiverTypeRef = when (declaration) {
is FirValueParameter -> declaration.returnTypeRef
is FirFunction -> declaration.receiverParameter?.type
is FirFunction -> declaration.receiverParameter?.typeRef
else -> null
}
@@ -173,7 +173,7 @@ object FirOptInUsageBaseChecker {
if (fir !is FirConstructor) {
// Without coneTypeSafe v fails in MT test (FirRenderer.kt)
fir.returnTypeRef.coneTypeSafe<ConeKotlinType>().addExperimentalities(context, result, visited)
fir.receiverParameter?.type?.coneType.addExperimentalities(context, result, visited)
fir.receiverParameter?.typeRef?.coneType.addExperimentalities(context, result, visited)
if (fir is FirSimpleFunction) {
fir.valueParameters.forEach {
it.returnTypeRef.coneType.addExperimentalities(context, result, visited)
@@ -65,7 +65,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
private fun visitClassAndChildren(klass: FirClass, type: ConeClassLikeType) {
val receiverParameter = buildReceiverParameter {
this.type = buildResolvedTypeRef {
typeRef = buildResolvedTypeRef {
this.type = type
}
}
@@ -246,7 +246,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
withLabelAndReceiverType(
labelName,
declaration,
receiverParameter?.type?.coneType
receiverParameter?.typeRef?.coneType
) {
visitNestedElements(declaration)
}
@@ -967,12 +967,12 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
}
private fun FlowContent.generateReceiver(declaration: FirCallableDeclaration) {
generateReceiver(declaration.receiverParameter?.type)
generateReceiver(declaration.receiverParameter)
}
private fun FlowContent.generateReceiver(receiverTypeRef: FirTypeRef?) {
receiverTypeRef ?: return
generate(receiverTypeRef)
private fun FlowContent.generateReceiver(receiverParameter: FirReceiverParameter?) {
receiverParameter ?: return
generate(receiverParameter.typeRef)
+"."
}
@@ -1119,7 +1119,7 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
private fun FlowContent.describeVerbose(symbol: FirCallableSymbol<*>, fir: FirFunction) {
describeTypeParameters(fir)
fir.receiverParameter?.type?.let {
fir.receiverParameter?.typeRef?.let {
+"("
generate(it)
+")."
@@ -1138,7 +1138,7 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
private fun FlowContent.describeVerbose(symbol: FirCallableSymbol<*>, fir: FirVariable) {
if (fir is FirTypeParametersOwner) describeTypeParameters(fir)
fir.receiverParameter?.type?.let {
fir.receiverParameter?.typeRef?.let {
+"("
generate(it)
+")."
@@ -1766,7 +1766,7 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
iline {
generateLabel(anonymousFunction.label)
keyword("fun ")
generateReceiver(anonymousFunction.receiverParameter?.type)
generateReceiver(anonymousFunction.receiverParameter)
+"("
generateList(anonymousFunction.valueParameters) {
@@ -129,7 +129,7 @@ class FirContractDeserializer(private val c: FirDeserializationContext) {
val name: String
val typeRef = if (valueParameterIndex < 0) {
name = "this"
ownerFunction.receiverParameter?.type
ownerFunction.receiverParameter?.typeRef
} else {
val parameter = ownerFunction.valueParameters.getOrNull(valueParameterIndex) ?: return null
name = parameter.name.asString()
@@ -371,7 +371,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
this.returnTypeRef = returnTypeRef
receiverParameter = proto.receiverType(c.typeTable)?.toTypeRef(local)?.let { receiverType ->
buildReceiverParameter {
type = receiverType
typeRef = receiverType
annotations += receiverAnnotations
}
}
@@ -476,7 +476,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
returnTypeRef = proto.returnType(local.typeTable).toTypeRef(local)
receiverParameter = proto.receiverType(local.typeTable)?.toTypeRef(local)?.let { receiverType ->
buildReceiverParameter {
type = receiverType
typeRef = receiverType
annotations += receiverAnnotations
}
}
@@ -331,7 +331,7 @@ class FirElementSerializer private constructor(
val receiverParameter = property.receiverParameter
if (receiverParameter != null) {
val receiverTypeRef = receiverParameter.type
val receiverTypeRef = receiverParameter.typeRef
if (useTypeTable()) {
builder.receiverTypeId = local.typeId(receiverTypeRef)
} else {
@@ -415,7 +415,7 @@ class FirElementSerializer private constructor(
val receiverParameter = function.receiverParameter
if (receiverParameter != null) {
val receiverTypeRef = receiverParameter.type
val receiverTypeRef = receiverParameter.typeRef
if (useTypeTable()) {
builder.receiverTypeId = local.typeId(receiverTypeRef)
} else {
@@ -154,7 +154,7 @@ open class FirJvmMangleComputer(
mangleType(builder, it.typeRef.coneType)
}
val receiverType = receiverParameter?.type ?: (this as? FirPropertyAccessor)?.propertySymbol?.fir?.receiverParameter?.type
val receiverType = receiverParameter?.typeRef ?: (this as? FirPropertyAccessor)?.propertySymbol?.fir?.receiverParameter?.typeRef
receiverType?.let {
builder.appendSignature(MangleConstant.EXTENSION_RECEIVER_PREFIX)
mangleType(builder, it.coneType)
@@ -317,7 +317,7 @@ open class FirJvmMangleComputer(
builder.appendSignature(MangleConstant.STATIC_MEMBER_MARK)
}
variable.receiverParameter?.type?.let {
variable.receiverParameter?.typeRef?.let {
builder.appendSignature(MangleConstant.EXTENSION_RECEIVER_PREFIX)
mangleType(builder, it.coneType)
}
@@ -231,7 +231,7 @@ class FirJvmSerializerExtension(
this is FirSimpleFunction && isInline && !isSuspend && !isParamAssertionsDisabled &&
!Visibilities.isPrivate(visibility) &&
(valueParameters.any { it.returnTypeRef.coneType.isBuiltinFunctionalType(session) } ||
receiverParameter?.type?.coneType?.isBuiltinFunctionalType(session) == true)
receiverParameter?.typeRef?.coneType?.isBuiltinFunctionalType(session) == true)
override fun serializeProperty(
property: FirProperty,
@@ -320,7 +320,7 @@ class FirJvmSerializerExtension(
private fun requiresSignature(function: FirFunction, desc: String): Boolean {
val sb = StringBuilder()
sb.append("(")
val receiverTypeRef = function.receiverParameter?.type
val receiverTypeRef = function.receiverParameter?.typeRef
if (receiverTypeRef != null) {
val receiverDesc = mapTypeDefault(receiverTypeRef) ?: return true
sb.append(receiverDesc)
@@ -196,7 +196,7 @@ private fun FirFunction.copyToFreeAnonymousFunction(approximator: AbstractTypeAp
returnTypeRef = function.returnTypeRef.approximated(approximator, typeParameterSet, toSuper = true)
receiverParameter = function.receiverParameter?.let { receiverParameter ->
buildReceiverParameterCopy(receiverParameter) {
type = receiverParameter.type.approximated(approximator, typeParameterSet, toSuper = false)
typeRef = receiverParameter.typeRef.approximated(approximator, typeParameterSet, toSuper = false)
}
}
@@ -247,7 +247,7 @@ internal fun FirProperty.copyToFreeProperty(approximator: AbstractTypeApproximat
returnTypeRef = property.returnTypeRef.approximated(approximator, typeParameterSet, toSuper = true)
receiverParameter = property.receiverParameter?.let { receiverParameter ->
buildReceiverParameterCopy(receiverParameter) {
type = receiverParameter.type.approximated(approximator, typeParameterSet, toSuper = false)
typeRef = receiverParameter.typeRef.approximated(approximator, typeParameterSet, toSuper = false)
}
}
name = property.name
@@ -355,7 +355,7 @@ class Fir2IrDeclarationStorage(
Name.identifier("\$this\$$suffix")
} ?: SpecialNames.THIS
declareThisReceiverParameter(
thisType = receiver.type.toIrType(typeContext),
thisType = receiver.typeRef.toIrType(typeContext),
thisOrigin = thisOrigin,
startOffset = startOffset,
endOffset = endOffset,
@@ -409,7 +409,7 @@ class CallAndReferenceGenerator(
qualifiedAccess.convertWithOffsets { startOffset, endOffset ->
val callableDeclaration = firSymbol?.fir as? FirCallableDeclaration
val targetType = callableDeclaration?.dispatchReceiverType?.toIrType()
?: callableDeclaration?.receiverParameter?.type?.toIrType()
?: callableDeclaration?.receiverParameter?.typeRef?.toIrType()
?: error("Couldn't get the proper receiver")
IrTypeOperatorCallImpl(
startOffset, endOffset, targetType,
@@ -1061,7 +1061,7 @@ class CallAndReferenceGenerator(
if (ownerFunction?.extensionReceiverParameter != null) {
extensionReceiver = qualifiedAccess.findIrExtensionReceiver(explicitReceiverExpression)?.let {
((qualifiedAccess.calleeReference as FirResolvedNamedReference)
.resolvedSymbol.fir as? FirCallableDeclaration)?.receiverParameter?.type?.let { receiverType ->
.resolvedSymbol.fir as? FirCallableDeclaration)?.receiverParameter?.typeRef?.let { receiverType ->
with(visitor.implicitCastInserter) {
it.cast(
qualifiedAccess.extensionReceiver,
@@ -68,7 +68,7 @@ class Fir2IrLazyPropertyAccessor(
override var extensionReceiverParameter: IrValueParameter? by lazyVar(lock) {
firParentProperty.receiverParameter?.let {
createThisReceiverParameter(it.type.toIrType(typeConverter, conversionTypeContext), it)
createThisReceiverParameter(it.typeRef.toIrType(typeConverter, conversionTypeContext), it)
}
}
@@ -60,7 +60,7 @@ class Fir2IrLazySimpleFunction(
override var extensionReceiverParameter: IrValueParameter? by lazyVar(lock) {
fir.receiverParameter?.let {
createThisReceiverParameter(it.type.toIrType(typeConverter), it)
createThisReceiverParameter(it.typeRef.toIrType(typeConverter), it)
}
}
@@ -307,7 +307,7 @@ class FirSignatureEnhancement(
returnTypeRef = newReturnTypeRef
receiverParameter = newReceiverTypeRef?.let { receiverType ->
buildReceiverParameter {
type = receiverType
typeRef = receiverType
annotations += firMethod.valueParameters.first().annotations
source = receiverType.source?.fakeElement(KtFakeSourceElementKind.ReceiverFromType)
}
@@ -510,7 +510,7 @@ class FirSignatureEnhancement(
object Receiver : TypeInSignature() {
override fun getTypeRef(member: FirCallableDeclaration): FirTypeRef {
if (member is FirJavaMethod) return member.valueParameters[0].returnTypeRef
return member.receiverParameter?.type!!
return member.receiverParameter?.typeRef!!
}
}
@@ -166,7 +166,7 @@ class JavaOverrideChecker internal constructor(
private fun FirCallableDeclaration.isTypeParameterDependent(): Boolean =
typeParameters.isNotEmpty() || returnTypeRef.isTypeParameterDependent() ||
receiverParameter?.type.isTypeParameterDependent() ||
receiverParameter?.typeRef.isTypeParameterDependent() ||
this is FirSimpleFunction && valueParameters.any { it.returnTypeRef.isTypeParameterDependent() }
private fun FirTypeRef.extractTypeParametersTo(result: MutableCollection<FirTypeParameterRef>) {
@@ -195,7 +195,7 @@ class JavaOverrideChecker internal constructor(
private fun FirCallableDeclaration.extractTypeParametersTo(result: MutableCollection<FirTypeParameterRef>) {
result += typeParameters
returnTypeRef.extractTypeParametersTo(result)
receiverParameter?.type?.extractTypeParametersTo(result)
receiverParameter?.typeRef?.extractTypeParametersTo(result)
if (this is FirSimpleFunction) {
this.valueParameters.forEach { it.returnTypeRef.extractTypeParametersTo(result) }
}
@@ -224,7 +224,7 @@ class JavaOverrideChecker internal constructor(
baseDeclaration.lazyResolveToPhase(FirResolvePhase.TYPES)
// NB: overrideCandidate is from Java and has no receiver
val receiverTypeRef = baseDeclaration.receiverParameter?.type
val receiverTypeRef = baseDeclaration.receiverParameter?.typeRef
val baseParameterTypes = listOfNotNull(receiverTypeRef) + baseDeclaration.valueParameters.map { it.returnTypeRef }
if (overrideCandidate.valueParameters.size != baseParameterTypes.size) return false
@@ -247,7 +247,7 @@ class JavaOverrideChecker internal constructor(
overrideCandidate.lazyResolveToPhase(FirResolvePhase.TYPES)
baseDeclaration.lazyResolveToPhase(FirResolvePhase.TYPES)
val receiverTypeRef = baseDeclaration.receiverParameter?.type
val receiverTypeRef = baseDeclaration.receiverParameter?.typeRef
return when (overrideCandidate) {
is FirSimpleFunction -> {
if (receiverTypeRef == null) {
@@ -259,7 +259,7 @@ class JavaOverrideChecker internal constructor(
}
}
is FirProperty -> {
val overrideReceiverTypeRef = overrideCandidate.receiverParameter?.type
val overrideReceiverTypeRef = overrideCandidate.receiverParameter?.typeRef
return when {
receiverTypeRef == null -> overrideReceiverTypeRef == null
overrideReceiverTypeRef == null -> false
@@ -61,7 +61,7 @@ class ConeEquivalentCallConflictResolver(
): Boolean {
if (first.symbol.callableId != second.symbol.callableId) return false
if (first.isExpect != second.isExpect) return false
if (first.receiverParameter?.type?.coneType != second.receiverParameter?.type?.coneType) {
if (first.receiverParameter?.typeRef?.coneType != second.receiverParameter?.typeRef?.coneType) {
return false
}
if (first is FirVariable != second is FirVariable) {
@@ -281,7 +281,7 @@ class FirClassSubstitutionScope(
forceTypeParametersRecreation = dispatchReceiverTypeForSubstitutedMembers.lookupTag != member.dispatchReceiverClassLookupTagOrNull()
)
val receiverType = member.receiverParameter?.type?.coneType
val receiverType = member.receiverParameter?.typeRef?.coneType
val newReceiverType = receiverType?.substitute(substitutor)
val newDispatchReceiverType = dispatchReceiverTypeForSubstitutedMembers.substitute(substitutor)
@@ -152,7 +152,7 @@ object FirFakeOverrideGenerator {
this.origin = origin
receiverParameter = baseConstructor.receiverParameter?.let { receiverParameter ->
buildReceiverParameterCopy(receiverParameter) {
type = receiverParameter.type.withReplacedConeType(null)
typeRef = receiverParameter.typeRef.withReplacedConeType(null)
}
}
@@ -269,7 +269,7 @@ object FirFakeOverrideGenerator {
if (this is FirSimpleFunctionBuilder) {
receiverParameter = baseFunction.receiverParameter?.let { receiverParameter ->
buildReceiverParameterCopy(receiverParameter) {
type = receiverParameter.type.withReplacedConeType(newReceiverType)
typeRef = receiverParameter.typeRef.withReplacedConeType(newReceiverType)
}
}
}
@@ -418,7 +418,7 @@ object FirFakeOverrideGenerator {
): Triple<ConeKotlinType?, List<ConeKotlinType?>, Maybe<ConeKotlinType?>> {
val copiedReceiverType = newReceiverType?.let {
substitutor.substituteOrNull(it)
} ?: baseCallable.receiverParameter?.type?.let {
} ?: baseCallable.receiverParameter?.typeRef?.let {
substitutor.substituteOrNull(it.coneType)
}
@@ -464,7 +464,7 @@ object FirFakeOverrideGenerator {
receiverParameter = baseProperty.receiverParameter?.let { receiverParameter ->
buildReceiverParameterCopy(receiverParameter) {
type = receiverParameter.type.withReplacedConeType(newReceiverType)
typeRef = receiverParameter.typeRef.withReplacedConeType(newReceiverType)
}
}
@@ -131,8 +131,8 @@ class FirStandardOverrideChecker(private val session: FirSession) : FirAbstractO
overrideCandidate.lazyResolveToPhase(FirResolvePhase.TYPES)
baseDeclaration.lazyResolveToPhase(FirResolvePhase.TYPES)
if (!isEqualReceiverTypes(
overrideCandidate.receiverParameter?.type,
baseDeclaration.receiverParameter?.type,
overrideCandidate.receiverParameter?.typeRef,
baseDeclaration.receiverParameter?.typeRef,
substitutor,
)
) return false
@@ -152,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.receiverParameter?.type, baseDeclaration.receiverParameter?.type, substitutor)
return isEqualReceiverTypes(overrideCandidate.receiverParameter?.typeRef, baseDeclaration.receiverParameter?.typeRef, substitutor)
}
}
@@ -240,7 +240,7 @@ fun ConeKotlinType.valueParameterTypesIncludingReceiver(session: FirSession): Li
}
val FirAnonymousFunction.returnType: ConeKotlinType? get() = returnTypeRef.coneTypeSafe()
val FirAnonymousFunction.receiverType: ConeKotlinType? get() = receiverParameter?.type?.coneTypeSafe()
val FirAnonymousFunction.receiverType: ConeKotlinType? get() = receiverParameter?.typeRef?.coneTypeSafe()
fun ConeTypeContext.isTypeMismatchDueToNullability(
actualType: ConeKotlinType,
@@ -573,13 +573,13 @@ fun FirTypeRef.asReceiverParameter(receiverAnnotations: List<FirAnnotationCall>?
return buildReceiverParameter {
source = typeRef.source?.fakeElement(KtFakeSourceElementKind.ReceiverFromType)
receiverAnnotations?.let { annotations += it.filterUseSiteTarget(AnnotationUseSiteTarget.RECEIVER) }
type = typeRef
this.typeRef = typeRef
}
}
fun FirImplicitTypeRef.asReceiverParameter(): FirReceiverParameter = buildReceiverParameter {
source = this@asReceiverParameter.source?.fakeElement(KtFakeSourceElementKind.ReceiverFromType)
type = this@asReceiverParameter
typeRef = this@asReceiverParameter
}
fun <T> FirCallableDeclaration.initContainingClassAttr(context: Context<T>) {
@@ -66,7 +66,7 @@ fun FirFunction.constructFunctionalType(isSuspend: Boolean = false): ConeLookupT
is FirSimpleFunction -> receiverParameter
is FirAnonymousFunction -> receiverParameter
else -> null
}?.type
}?.typeRef
val parameters = valueParameters.map {
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeErrorType(
@@ -389,7 +389,7 @@ private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(): ConeLookupTagB
return createFunctionalType(
parameterTypes,
receiverType = receiverParameter?.type?.coneType,
receiverType = receiverParameter?.typeRef?.coneType,
rawReturnType = returnTypeRef.coneType,
isSuspend = this.isSuspend
)
@@ -175,7 +175,7 @@ abstract class AbstractConeCallConflictResolver(
): List<TypeWithConversion> {
return buildList {
val session = inferenceComponents.session
addIfNotNull(called.receiverParameter?.type?.coneType?.fullyExpandedType(session)?.let { TypeWithConversion(it) })
addIfNotNull(called.receiverParameter?.typeRef?.coneType?.fullyExpandedType(session)?.let { TypeWithConversion(it) })
val typeForCallableReference = call.resultingTypeForCallableReference
if (typeForCallableReference != null) {
// Return type isn't needed here v
@@ -70,7 +70,7 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() {
}
val declarationReceiverType: ConeKotlinType? =
fir.receiverParameter?.type?.coneType?.let(candidate.substitutor::substituteOrSelf)
fir.receiverParameter?.typeRef?.coneType?.let(candidate.substitutor::substituteOrSelf)
if (resultingReceiverType != null && declarationReceiverType != null) {
val capturedReceiver = context.session.typeContext.captureFromExpression(resultingReceiverType) ?: resultingReceiverType
@@ -319,7 +319,7 @@ private class TypeAliasConstructorsSubstitutingScope(
//
receiverParameter = originalConstructorSymbol.fir.returnTypeRef.withReplacedConeType(outerType).let {
buildReceiverParameter {
type = it
typeRef = it
}
}
}
@@ -128,7 +128,7 @@ object CheckExtensionReceiver : ResolutionStage() {
private fun Candidate.getExpectedReceiverType(): ConeKotlinType? {
val callableSymbol = symbol as? FirCallableSymbol<*> ?: return null
return callableSymbol.fir.receiverParameter?.type?.coneType
return callableSymbol.fir.receiverParameter?.typeRef?.coneType
}
}
@@ -390,7 +390,7 @@ class ScopeTowerLevel(
candidate: FirCallableSymbol<*>,
processor: TowerScopeLevelProcessor<T>
) {
val candidateReceiverTypeRef = candidate.fir.receiverParameter?.type
val candidateReceiverTypeRef = candidate.fir.receiverParameter?.typeRef
if (withHideMembersOnly && candidate.getAnnotationByClassId(HidesMembers) == null) {
return
}
@@ -69,7 +69,7 @@ object ConeConstraintSystemUtilContext : ConstraintSystemUtilContext {
else null
} else { // function expression - all types are explicit, shouldn't return null
buildList {
atom.receiverParameter?.type?.coneType?.let { add(it) }
atom.receiverParameter?.typeRef?.coneType?.let { add(it) }
addAll(atom.collectDeclaredValueParameterTypes())
}
}
@@ -90,7 +90,7 @@ object ConeConstraintSystemUtilContext : ConstraintSystemUtilContext {
require(this is PostponedResolvedAtom)
return this is LambdaWithTypeVariableAsExpectedTypeAtom &&
!this.atom.anonymousFunction.isLambda &&
this.atom.anonymousFunction.receiverParameter?.type?.coneType != null
this.atom.anonymousFunction.receiverParameter?.typeRef?.coneType != null
}
override fun PostponedAtomWithRevisableExpectedType.isLambda(): Boolean {
@@ -310,7 +310,7 @@ class FirCallCompleter(
lambdaArgument.receiverParameter?.let { receiverParameter ->
receiverType?.approximateLambdaInputType()?.let { approximatedType ->
receiverParameter.apply {
replaceType(type.resolvedTypeFromPrototype(approximatedType))
replaceTypeRef(typeRef.resolvedTypeFromPrototype(approximatedType))
}
}
}
@@ -399,7 +399,7 @@ internal fun FirFunction.isFunctionForExpectTypeFromCastFeature(): Boolean {
coneTypeSafe<ConeKotlinType>()
?.contains { (it.unwrap() as? ConeTypeParameterType)?.lookupTag == typeParameter.symbol.toLookupTag() } != false
if (valueParameters.any { it.returnTypeRef.isBadType() } || receiverParameter?.type?.isBadType() == true) return false
if (valueParameters.any { it.returnTypeRef.isBadType() } || receiverParameter?.typeRef?.isBadType() == true) return false
return true
}
@@ -131,7 +131,7 @@ class FirCallCompletionResultsWriterTransformer(
var extensionReceiver = subCandidate.chosenExtensionReceiverExpression()
if (!declaration.isWrappedIntegerOperator()) {
val expectedDispatchReceiverType = (declaration as? FirCallableDeclaration)?.dispatchReceiverType
val expectedExtensionReceiverType = (declaration as? FirCallableDeclaration)?.receiverParameter?.type?.coneType
val expectedExtensionReceiverType = (declaration as? FirCallableDeclaration)?.receiverParameter?.typeRef?.coneType
dispatchReceiver = dispatchReceiver.transformSingle(integerOperatorApproximator, expectedDispatchReceiverType)
extensionReceiver = extensionReceiver.transformSingle(integerOperatorApproximator, expectedExtensionReceiverType)
}
@@ -615,10 +615,10 @@ class FirCallCompletionResultsWriterTransformer(
var needUpdateLambdaType = false
val receiverParameter = anonymousFunction.receiverParameter
val initialReceiverType = receiverParameter?.type?.coneTypeSafe<ConeKotlinType>()
val initialReceiverType = receiverParameter?.typeRef?.coneTypeSafe<ConeKotlinType>()
val resultReceiverType = initialReceiverType?.let { finalSubstitutor.substituteOrNull(it) }
if (resultReceiverType != null) {
receiverParameter.replaceType(receiverParameter.type.resolvedTypeFromPrototype(resultReceiverType))
receiverParameter.replaceTypeRef(receiverParameter.typeRef.resolvedTypeFromPrototype(resultReceiverType))
needUpdateLambdaType = true
}
@@ -304,7 +304,7 @@ class FirStatusResolver(
if (declaration is FirConstructor) return false
if (containingClass.typeParameters.all { it.symbol.variance == Variance.INVARIANT }) return false
if (declaration.receiverParameter?.type?.contradictsWith(Variance.IN_VARIANCE) == true) {
if (declaration.receiverParameter?.typeRef?.contradictsWith(Variance.IN_VARIANCE) == true) {
return true
}
if (declaration.returnTypeRef.contradictsWith(
@@ -115,7 +115,7 @@ open class FirTypeResolveTransformer(
}
override fun transformReceiverParameter(receiverParameter: FirReceiverParameter, data: Any?): FirReceiverParameter {
return receiverParameter.transformAnnotations(this, data).transformType(this, data)
return receiverParameter.transformAnnotations(this, data).transformTypeRef(this, data)
}
override fun transformProperty(property: FirProperty, data: Any?): FirProperty {
@@ -569,7 +569,7 @@ class BodyResolveContext(
for (parameter in function.valueParameters) {
storeVariable(parameter, holder.session)
}
val receiverTypeRef = function.receiverParameter?.type
val receiverTypeRef = function.receiverParameter?.typeRef
val type = receiverTypeRef?.coneType
val additionalLabelName = type?.labelName()
withLabelAndReceiverType(function.name, function, type, holder, additionalLabelName, f)
@@ -622,7 +622,7 @@ class BodyResolveContext(
}
return withTowerDataCleanup {
addLocalScope(FirLocalScope(holder.session))
val receiverTypeRef = anonymousFunction.receiverParameter?.type
val receiverTypeRef = anonymousFunction.receiverParameter?.typeRef
val labelName = anonymousFunction.label?.name?.let { Name.identifier(it) }
withContainer(anonymousFunction) {
withLabelAndReceiverType(labelName, anonymousFunction, receiverTypeRef?.coneType, holder) {
@@ -717,7 +717,7 @@ class BodyResolveContext(
}
}
return withTowerDataCleanup {
val receiverTypeRef = property.receiverParameter?.type
val receiverTypeRef = property.receiverParameter?.typeRef
addLocalScope(FirLocalScope(holder.session))
if (!forContracts && receiverTypeRef == null && property.returnTypeRef !is FirImplicitTypeRef &&
!property.isLocal && property.delegate == null
@@ -232,7 +232,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirAbstractBodyResolve
val typeRef = propertyReferenceAccess.typeRef
if (typeRef is FirResolvedTypeRef && property.returnTypeRef is FirResolvedTypeRef) {
val typeArguments = (typeRef.type as ConeClassLikeType).typeArguments
val extensionType = property.receiverParameter?.type?.coneType
val extensionType = property.receiverParameter?.typeRef?.coneType
val dispatchType = context.containingClass?.let { containingClass ->
containingClass.symbol.constructStarProjectedType(containingClass.typeParameters.size)
}
@@ -815,10 +815,10 @@ open class FirDeclarationsResolveTransformer(transformer: FirAbstractBodyResolve
}
val returnTypeRefFromResolvedAtom = resolvedLambdaAtom?.returnType?.let { lambda.returnTypeRef.resolvedTypeFromPrototype(it) }
lambda = buildAnonymousFunctionCopy(lambda) {
receiverParameter = lambda.receiverParameter?.takeIf { it.type !is FirImplicitTypeRef }
receiverParameter = lambda.receiverParameter?.takeIf { it.typeRef !is FirImplicitTypeRef }
?: resolvedLambdaAtom?.receiver?.let { coneKotlinType ->
lambda.receiverParameter?.apply {
replaceType(type.resolvedTypeFromPrototype(coneKotlinType))
replaceTypeRef(typeRef.resolvedTypeFromPrototype(coneKotlinType))
}
}
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.contracts.impl.FirEmptyContractDescription
import org.jetbrains.kotlin.fir.contracts.toFirEffectDeclaration
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.buildAnonymousFunction
import org.jetbrains.kotlin.fir.declarations.builder.buildReceiverParameter
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
import org.jetbrains.kotlin.fir.errorTypeFromPrototype
import org.jetbrains.kotlin.fir.expressions.*
@@ -169,7 +170,7 @@ abstract class FirAbstractContractResolveTransformerDispatcher(
origin = FirDeclarationOrigin.Source
returnTypeRef = buildImplicitTypeRef()
receiverParameter = buildReceiverParameter {
type = buildImplicitTypeRef()
typeRef = buildImplicitTypeRef()
}
symbol = FirAnonymousFunctionSymbol()
isLambda = true
@@ -121,7 +121,7 @@ private class FirDeclarationsResolveTransformerForArgumentAnnotations(
}
override fun transformReceiverParameter(receiverParameter: FirReceiverParameter, data: ResolutionMode): FirReceiverParameter {
return receiverParameter.transformAnnotations(transformer, data).transformType(transformer, data)
return receiverParameter.transformAnnotations(transformer, data).transformTypeRef(transformer, data)
}
override fun transformField(field: FirField, data: ResolutionMode): FirField {
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.fir.visitors.*
abstract class FirReceiverParameter : FirPureAbstractElement(), FirAnnotationContainer {
abstract override val source: KtSourceElement?
abstract val type: FirTypeRef
abstract val typeRef: FirTypeRef
abstract override val annotations: List<FirAnnotation>
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitReceiverParameter(this, data)
@@ -29,9 +29,9 @@ abstract class FirReceiverParameter : FirPureAbstractElement(), FirAnnotationCon
override fun <E: FirElement, D> transform(transformer: FirTransformer<D>, data: D): E =
transformer.transformReceiverParameter(this, data) as E
abstract fun replaceType(newType: FirTypeRef)
abstract fun replaceTypeRef(newTypeRef: FirTypeRef)
abstract fun <D> transformType(transformer: FirTransformer<D>, data: D): FirReceiverParameter
abstract fun <D> transformTypeRef(transformer: FirTransformer<D>, data: D): FirReceiverParameter
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirReceiverParameter
}
@@ -25,13 +25,13 @@ import org.jetbrains.kotlin.fir.visitors.*
@FirBuilderDsl
class FirReceiverParameterBuilder : FirAnnotationContainerBuilder {
override var source: KtSourceElement? = null
lateinit var type: FirTypeRef
lateinit var typeRef: FirTypeRef
override val annotations: MutableList<FirAnnotation> = mutableListOf()
override fun build(): FirReceiverParameter {
return FirReceiverParameterImpl(
source,
type,
typeRef,
annotations,
)
}
@@ -53,7 +53,7 @@ inline fun buildReceiverParameterCopy(original: FirReceiverParameter, init: FirR
}
val copyBuilder = FirReceiverParameterBuilder()
copyBuilder.source = original.source
copyBuilder.type = original.type
copyBuilder.typeRef = original.typeRef
copyBuilder.annotations.addAll(original.annotations)
return copyBuilder.apply(init).build()
}
@@ -20,22 +20,22 @@ import org.jetbrains.kotlin.fir.visitors.*
internal class FirReceiverParameterImpl(
override val source: KtSourceElement?,
override var type: FirTypeRef,
override var typeRef: FirTypeRef,
override val annotations: MutableList<FirAnnotation>,
) : FirReceiverParameter() {
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
type.accept(visitor, data)
typeRef.accept(visitor, data)
annotations.forEach { it.accept(visitor, data) }
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirReceiverParameterImpl {
transformType(transformer, data)
transformTypeRef(transformer, data)
transformAnnotations(transformer, data)
return this
}
override fun <D> transformType(transformer: FirTransformer<D>, data: D): FirReceiverParameterImpl {
type = type.transform(transformer, data)
override fun <D> transformTypeRef(transformer: FirTransformer<D>, data: D): FirReceiverParameterImpl {
typeRef = typeRef.transform(transformer, data)
return this
}
@@ -44,7 +44,7 @@ internal class FirReceiverParameterImpl(
return this
}
override fun replaceType(newType: FirTypeRef) {
type = newType
override fun replaceTypeRef(newTypeRef: FirTypeRef) {
typeRef = newTypeRef
}
}
@@ -184,7 +184,7 @@ class FirRenderer(
print(" ")
if (receiverParameter != null) {
annotationRenderer?.render(receiverParameter, AnnotationUseSiteTarget.RECEIVER)
receiverParameter.type.accept(this)
receiverParameter.typeRef.accept(this)
print(".")
}
when (callableDeclaration) {
@@ -304,7 +304,7 @@ class FirRenderer(
override fun visitReceiverParameter(receiverParameter: FirReceiverParameter) {
print("<explicit receiver parameter>: ")
annotationRenderer?.render(receiverParameter)
receiverParameter.type.accept(this)
receiverParameter.typeRef.accept(this)
}
override fun visitSimpleFunction(simpleFunction: FirSimpleFunction) {
@@ -353,7 +353,7 @@ class FirRenderer(
print(" ")
val receiverParameter = anonymousFunction.receiverParameter
if (receiverParameter != null) {
receiverParameter.type.accept(this)
receiverParameter.typeRef.accept(this)
print(".")
}
print("<anonymous>")
@@ -29,13 +29,13 @@ abstract class FirCallableSymbol<D : FirCallableDeclaration> : FirBasedSymbol<D>
val resolvedReceiverTypeRef: FirResolvedTypeRef?
get() {
ensureType(fir.receiverParameter?.type)
return fir.receiverParameter?.type as FirResolvedTypeRef?
ensureType(fir.receiverParameter?.typeRef)
return fir.receiverParameter?.typeRef as FirResolvedTypeRef?
}
val receiverParameter: FirAnnotationContainer?
get() {
ensureType(fir.receiverParameter?.type)
ensureType(fir.receiverParameter?.typeRef)
return fir.receiverParameter
}
@@ -569,6 +569,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
"FirArrayOfCallImpl",
"FirIntegerLiteralOperatorCallImpl",
"FirContextReceiverImpl",
"FirReceiverParameterImpl",
"FirClassReferenceExpressionImpl",
"FirGetClassCallImpl",
"FirSmartCastExpressionImpl"
@@ -394,7 +394,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
}
receiverParameter.configure {
+field("type", typeRef).withTransform().withReplace()
+typeRefField.withTransform()
+annotations
}
@@ -270,7 +270,7 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
when (psi) {
is KtLambdaArgument -> {
val firLambda = (psi.firstOfType<FirLambdaArgumentExpression>()?.expression as? FirAnonymousFunctionExpression)?.anonymousFunction
firLambda?.receiverParameter?.type?.let {
firLambda?.receiverParameter?.typeRef?.let {
lastCallWithLambda = psi.getLambdaExpression()?.firstOfType<FirLabel>()?.name
implicitReceivers += it.coneType
psi.accept(this)
@@ -537,7 +537,7 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
data.append(if (fir.isVar) "var" else "val").append(" ")
renderListInTriangles(fir.typeParameters, data, withSpace = true)
val receiver = fir.receiverParameter?.type?.render()
val receiver = fir.receiverParameter?.typeRef?.render()
when {
receiver != null -> data.append(receiver).append(".").append(symbol.callableId.callableName)
fir.dispatchReceiverType != null -> {
@@ -560,7 +560,7 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
val id = getSymbolId(symbol)
val callableName = symbol.callableId.callableName
val receiverParameterType = fir.receiverParameter?.type
val receiverParameterType = fir.receiverParameter?.typeRef
if (call == null) {
// call is null for callable reference