Fir2IrDeclarationStorage: drop redundant 'with' + fix formatting

This commit is contained in:
Mikhail Glukhikh
2022-11-27 23:07:59 +01:00
committed by Space Team
parent 237f357016
commit 91a3c78844
@@ -348,46 +348,45 @@ class Fir2IrDeclarationStorage(
} }
} }
} }
with(classifierStorage) {
val thisOrigin = IrDeclarationOrigin.DEFINED val thisOrigin = IrDeclarationOrigin.DEFINED
if (function !is FirConstructor) { if (function !is FirConstructor) {
val receiver: FirReceiverParameter? = val receiver: FirReceiverParameter? =
if (function !is FirPropertyAccessor && function != null) function.receiverParameter if (function !is FirPropertyAccessor && function != null) function.receiverParameter
else parentPropertyReceiver else parentPropertyReceiver
if (receiver != null) { if (receiver != null) {
extensionReceiverParameter = receiver.convertWithOffsets { startOffset, endOffset -> extensionReceiverParameter = receiver.convertWithOffsets { startOffset, endOffset ->
val name = (function as? FirAnonymousFunction)?.label?.name?.let { val name = (function as? FirAnonymousFunction)?.label?.name?.let {
val suffix = it.takeIf(Name::isValidIdentifier) ?: "\$receiver" val suffix = it.takeIf(Name::isValidIdentifier) ?: "\$receiver"
Name.identifier("\$this\$$suffix") Name.identifier("\$this\$$suffix")
} ?: SpecialNames.THIS } ?: SpecialNames.THIS
declareThisReceiverParameter( declareThisReceiverParameter(
thisType = receiver.typeRef.toIrType(typeContext), thisType = receiver.typeRef.toIrType(typeContext),
thisOrigin = thisOrigin, thisOrigin = thisOrigin,
startOffset = startOffset, startOffset = startOffset,
endOffset = endOffset, endOffset = endOffset,
name = name, name = name,
explicitReceiver = receiver, explicitReceiver = receiver,
)
}
}
// See [LocalDeclarationsLowering]: "local function must not have dispatch receiver."
val isLocal = function is FirSimpleFunction && function.isLocal
if (function !is FirAnonymousFunction && containingClass != null && !isStatic && !isLocal) {
dispatchReceiverParameter = declareThisReceiverParameter(
thisType = containingClass.thisReceiver?.type ?: error("No this receiver"),
thisOrigin = thisOrigin
)
}
} else {
// Set dispatch receiver parameter for inner class's constructor.
val outerClass = containingClass?.parentClassOrNull
if (containingClass?.isInner == true && outerClass != null) {
dispatchReceiverParameter = declareThisReceiverParameter(
thisType = outerClass.thisReceiver!!.type,
thisOrigin = thisOrigin
) )
} }
} }
// See [LocalDeclarationsLowering]: "local function must not have dispatch receiver."
val isLocal = function is FirSimpleFunction && function.isLocal
if (function !is FirAnonymousFunction && containingClass != null && !isStatic && !isLocal) {
dispatchReceiverParameter = declareThisReceiverParameter(
thisType = containingClass.thisReceiver?.type ?: error("No this receiver"),
thisOrigin = thisOrigin
)
}
} else {
// Set dispatch receiver parameter for inner class's constructor.
val outerClass = containingClass?.parentClassOrNull
if (containingClass?.isInner == true && outerClass != null) {
dispatchReceiverParameter = declareThisReceiverParameter(
thisType = outerClass.thisReceiver!!.type,
thisOrigin = thisOrigin
)
}
} }
} }
@@ -1440,7 +1439,8 @@ class Fir2IrDeclarationStorage(
firPropertySymbol.dispatchReceiverClassLookupTagOrNull() != firPropertySymbol.dispatchReceiverClassLookupTagOrNull() !=
firPropertySymbol.originalForSubstitutionOverride?.dispatchReceiverClassLookupTagOrNull() firPropertySymbol.originalForSubstitutionOverride?.dispatchReceiverClassLookupTagOrNull()
Fir2IrLazyProperty( Fir2IrLazyProperty(
components, startOffset, endOffset, declarationOrigin, fir, (lazyParent as? Fir2IrLazyClass)?.fir, symbol, isFakeOverride components, startOffset, endOffset, declarationOrigin,
fir, (lazyParent as? Fir2IrLazyClass)?.fir, symbol, isFakeOverride
).apply { ).apply {
this.parent = lazyParent this.parent = lazyParent
} }