[FIR] Fix containingClassForStaticMemberAttr initialization
This commit is contained in:
+2
@@ -265,6 +265,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
c.annotationDeserializer.loadPropertyGetterAnnotations(
|
||||
c.containerSource, proto, local.nameResolver, local.typeTable, getterFlags
|
||||
)
|
||||
containingClassForStaticMemberAttr = c.dispatchReceiver?.lookupTag
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,6 +322,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
c.annotationDeserializer.loadPropertySetterAnnotations(
|
||||
c.containerSource, proto, local.nameResolver, local.typeTable, setterFlags
|
||||
)
|
||||
containingClassForStaticMemberAttr = c.dispatchReceiver?.lookupTag
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -519,7 +519,8 @@ class DeclarationsConverter(
|
||||
baseModuleData,
|
||||
callableIdForName(it.firValueParameter.name),
|
||||
classWrapper.hasExpect(),
|
||||
currentDispatchReceiverType()
|
||||
currentDispatchReceiverType(),
|
||||
context
|
||||
)
|
||||
}
|
||||
addDeclarations(properties)
|
||||
@@ -1106,7 +1107,8 @@ class DeclarationsConverter(
|
||||
classWrapper?.classBuilder?.ownerRegularOrAnonymousObjectSymbol,
|
||||
classWrapper?.classBuilder?.ownerRegularClassTypeParametersCount,
|
||||
isExtension = false,
|
||||
receiver = receiver
|
||||
receiver = receiver,
|
||||
context = context
|
||||
)
|
||||
} else {
|
||||
this.isLocal = false
|
||||
@@ -1173,6 +1175,7 @@ class DeclarationsConverter(
|
||||
baseModuleData,
|
||||
classWrapper?.classBuilder?.ownerRegularOrAnonymousObjectSymbol,
|
||||
classWrapper?.classBuilder?.ownerRegularClassTypeParametersCount,
|
||||
context,
|
||||
isExtension = receiverType != null,
|
||||
receiver = receiver
|
||||
)
|
||||
|
||||
+7
-4
@@ -6,6 +6,8 @@
|
||||
package org.jetbrains.kotlin.fir.lightTree.fir
|
||||
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.builder.Context
|
||||
import org.jetbrains.kotlin.fir.builder.initContainingClassAttr
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||
@@ -35,11 +37,12 @@ class ValueParameter(
|
||||
return isVal || isVar
|
||||
}
|
||||
|
||||
fun toFirProperty(
|
||||
fun <T> toFirProperty(
|
||||
moduleData: FirModuleData,
|
||||
callableId: CallableId,
|
||||
isExpect: Boolean,
|
||||
currentDispatchReceiver: ConeClassLikeType?
|
||||
currentDispatchReceiver: ConeClassLikeType?,
|
||||
context: Context<T>
|
||||
): FirProperty {
|
||||
val name = this.firValueParameter.name
|
||||
var type = this.firValueParameter.returnTypeRef
|
||||
@@ -83,7 +86,7 @@ class ValueParameter(
|
||||
type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor),
|
||||
modifiers.getVisibility(),
|
||||
symbol,
|
||||
)
|
||||
).also { it.initContainingClassAttr(context) }
|
||||
setter = if (this.isVar) FirDefaultPropertySetter(
|
||||
defaultAccessorSource,
|
||||
moduleData,
|
||||
@@ -91,7 +94,7 @@ class ValueParameter(
|
||||
type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor),
|
||||
modifiers.getVisibility(),
|
||||
symbol,
|
||||
) else null
|
||||
).also { it.initContainingClassAttr(context) } else null
|
||||
}.apply {
|
||||
if (firValueParameter.isVararg) {
|
||||
this.isFromVararg = true
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
@@ -172,8 +173,12 @@ open class RawFirBuilder(
|
||||
|
||||
open fun convertProperty(
|
||||
property: KtProperty, ownerRegularOrAnonymousObjectSymbol: FirClassSymbol<*>?,
|
||||
ownerRegularClassTypeParametersCount: Int?,
|
||||
): FirProperty = property.toFirProperty(ownerRegularOrAnonymousObjectSymbol, ownerRegularClassTypeParametersCount)
|
||||
ownerRegularClassTypeParametersCount: Int?
|
||||
): FirProperty = property.toFirProperty(
|
||||
ownerRegularOrAnonymousObjectSymbol,
|
||||
ownerRegularClassTypeParametersCount,
|
||||
context
|
||||
)
|
||||
|
||||
open fun convertValueParameter(
|
||||
valueParameter: KtParameter,
|
||||
@@ -571,7 +576,7 @@ open class RawFirBuilder(
|
||||
type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor),
|
||||
visibility,
|
||||
symbol,
|
||||
)
|
||||
).also { it.initContainingClassAttr() }
|
||||
setter = if (isMutable) FirDefaultPropertySetter(
|
||||
defaultAccessorSource,
|
||||
baseModuleData,
|
||||
@@ -579,7 +584,7 @@ open class RawFirBuilder(
|
||||
type.copyWithNewSourceKind(FirFakeSourceElementKind.DefaultAccessor),
|
||||
visibility,
|
||||
symbol,
|
||||
) else null
|
||||
).also { it.initContainingClassAttr() } else null
|
||||
extractAnnotationsTo(this)
|
||||
|
||||
dispatchReceiverType = currentDispatchReceiverType()
|
||||
@@ -1439,9 +1444,10 @@ open class RawFirBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtProperty.toFirProperty(
|
||||
private fun <T> KtProperty.toFirProperty(
|
||||
ownerRegularOrAnonymousObjectSymbol: FirClassSymbol<*>?,
|
||||
ownerRegularClassTypeParametersCount: Int?,
|
||||
context: Context<T>
|
||||
): FirProperty {
|
||||
val propertyType = typeReference.toFirOrImplicitType()
|
||||
val propertyName = nameAsSafeName
|
||||
@@ -1497,7 +1503,8 @@ open class RawFirBuilder(
|
||||
ownerRegularOrAnonymousObjectSymbol = null,
|
||||
ownerRegularClassTypeParametersCount = null,
|
||||
isExtension = false,
|
||||
receiver = extractDelegateExpression()
|
||||
receiver = extractDelegateExpression(),
|
||||
context = context
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -1556,6 +1563,7 @@ open class RawFirBuilder(
|
||||
baseModuleData,
|
||||
ownerRegularOrAnonymousObjectSymbol,
|
||||
ownerRegularClassTypeParametersCount,
|
||||
context,
|
||||
isExtension = receiverTypeReference != null,
|
||||
receiver = extractDelegateExpression()
|
||||
)
|
||||
@@ -1580,7 +1588,11 @@ open class RawFirBuilder(
|
||||
}
|
||||
|
||||
override fun visitProperty(property: KtProperty, data: Unit): FirElement {
|
||||
return property.toFirProperty(ownerRegularOrAnonymousObjectSymbol = null, ownerRegularClassTypeParametersCount = null)
|
||||
return property.toFirProperty(
|
||||
ownerRegularOrAnonymousObjectSymbol = null,
|
||||
ownerRegularClassTypeParametersCount = null,
|
||||
context = context
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitTypeReference(typeReference: KtTypeReference, data: Unit): FirElement {
|
||||
|
||||
+2
-3
@@ -129,7 +129,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
else -> CallableId(context.packageFqName, context.className, name)
|
||||
}
|
||||
|
||||
fun currentDispatchReceiverType(): ConeClassLikeType? = context.dispatchReceiverTypesStack.lastOrNull()
|
||||
fun currentDispatchReceiverType(): ConeClassLikeType? = currentDispatchReceiverType(context)
|
||||
|
||||
fun callableIdForClassConstructor() =
|
||||
if (context.className == FqName.ROOT) CallableId(context.packageFqName, Name.special("<anonymous-init>"))
|
||||
@@ -1183,8 +1183,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
}
|
||||
|
||||
protected fun FirCallableDeclaration.initContainingClassAttr() {
|
||||
val currentDispatchReceiverType = currentDispatchReceiverType() ?: return
|
||||
containingClassForStaticMemberAttr = currentDispatchReceiverType.lookupTag
|
||||
initContainingClassAttr(context)
|
||||
}
|
||||
|
||||
private fun FirVariable.toQualifiedAccess(): FirQualifiedAccessExpression = buildPropertyAccessExpression {
|
||||
|
||||
+15
-1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.contracts.FirContractDescription
|
||||
import org.jetbrains.kotlin.fir.contracts.builder.buildLegacyRawContractDescription
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.FirVariable
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.*
|
||||
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference
|
||||
import org.jetbrains.kotlin.fir.symbols.constructStarProjectedType
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.ConeStarProjection
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildImplicitTypeRef
|
||||
@@ -333,11 +335,12 @@ val FirClassBuilder.ownerRegularOrAnonymousObjectSymbol
|
||||
val FirClassBuilder.ownerRegularClassTypeParametersCount
|
||||
get() = if (this is FirRegularClassBuilder) typeParameters.size else null
|
||||
|
||||
fun FirPropertyBuilder.generateAccessorsByDelegate(
|
||||
fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
|
||||
delegateBuilder: FirWrappedDelegateExpressionBuilder?,
|
||||
moduleData: FirModuleData,
|
||||
ownerRegularOrAnonymousObjectSymbol: FirClassSymbol<*>?,
|
||||
ownerRegularClassTypeParametersCount: Int?,
|
||||
context: Context<T>,
|
||||
isExtension: Boolean,
|
||||
receiver: FirExpression?
|
||||
) {
|
||||
@@ -466,6 +469,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate(
|
||||
propertySymbol = this@generateAccessorsByDelegate.symbol
|
||||
}.also {
|
||||
returnTarget.bind(it)
|
||||
it.initContainingClassAttr(context)
|
||||
}
|
||||
}
|
||||
if (isVar && (setter == null || setter is FirDefaultPropertyAccessor)) {
|
||||
@@ -518,6 +522,8 @@ fun FirPropertyBuilder.generateAccessorsByDelegate(
|
||||
this.annotations.addAll(annotations)
|
||||
}
|
||||
propertySymbol = this@generateAccessorsByDelegate.symbol
|
||||
}.also {
|
||||
it.initContainingClassAttr(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -574,6 +580,14 @@ fun FirQualifiedAccess.wrapWithSafeCall(receiver: FirExpression, source: FirSour
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> FirCallableDeclaration.initContainingClassAttr(context: Context<T>) {
|
||||
containingClassForStaticMemberAttr = currentDispatchReceiverType(context)?.lookupTag ?: return
|
||||
}
|
||||
|
||||
fun <T> currentDispatchReceiverType(context: Context<T>): ConeClassLikeType? {
|
||||
return context.dispatchReceiverTypesStack.lastOrNull()
|
||||
}
|
||||
|
||||
val CharSequence.isUnderscore: Boolean
|
||||
get() = all { it == '_' }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user