JVM IR: process type arguments for function references in DefaultImpls
Local functions for lambdas declared in DefaultImpls are now also
getting additional type parameters from the containing class (see
4dd794c2d2), so function references to them should be adapted similarly
to normal calls.
This change fixes
`box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt`.
This commit is contained in:
@@ -244,18 +244,22 @@ fun createDelegatingCallWithPlaceholderTypeArguments(existingCall: IrCall, redir
|
||||
valueArgumentsCount = redirectTarget.valueParameters.size,
|
||||
origin = existingCall.origin
|
||||
).apply {
|
||||
copyValueArgumentsFrom(
|
||||
existingCall,
|
||||
existingCall.symbol.owner,
|
||||
this.symbol.owner,
|
||||
receiversAsArguments = true,
|
||||
argumentsAsReceivers = false
|
||||
)
|
||||
var offset = 0
|
||||
existingCall.symbol.owner.parentAsClass.typeParameters.forEach { _ ->
|
||||
putTypeArgument(offset++, createPlaceholderAnyNType(irBuiltIns))
|
||||
}
|
||||
for (i in 0 until (existingCall.typeArgumentsCount)) {
|
||||
putTypeArgument(i + offset, existingCall.getTypeArgument(i))
|
||||
}
|
||||
}
|
||||
copyFromWithPlaceholderTypeArguments(existingCall, irBuiltIns)
|
||||
}
|
||||
|
||||
fun IrFunctionAccessExpression.copyFromWithPlaceholderTypeArguments(existingCall: IrFunctionAccessExpression, irBuiltIns: IrBuiltIns) {
|
||||
copyValueArgumentsFrom(
|
||||
existingCall,
|
||||
existingCall.symbol.owner,
|
||||
this.symbol.owner,
|
||||
receiversAsArguments = true,
|
||||
argumentsAsReceivers = false,
|
||||
)
|
||||
var offset = 0
|
||||
existingCall.symbol.owner.parentAsClass.typeParameters.forEach { _ ->
|
||||
putTypeArgument(offset++, createPlaceholderAnyNType(irBuiltIns))
|
||||
}
|
||||
for (i in 0 until existingCall.typeArgumentsCount) {
|
||||
putTypeArgument(i + offset, existingCall.getTypeArgument(i))
|
||||
}
|
||||
}
|
||||
|
||||
+4
-8
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.common.ir.moveBodyTo
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.copyFromWithPlaceholderTypeArguments
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.createDelegatingCallWithPlaceholderTypeArguments
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.createPlaceholderAnyNType
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.hasJvmDefault
|
||||
@@ -264,15 +265,10 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
if (newFunction != null) {
|
||||
with(expression) {
|
||||
IrFunctionReferenceImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
type,
|
||||
newFunction.symbol,
|
||||
typeArgumentsCount,
|
||||
expression.reflectionTarget,
|
||||
origin
|
||||
startOffset, endOffset, type, newFunction.symbol, newFunction.typeParameters.size, newFunction.valueParameters.size,
|
||||
expression.reflectionTarget, origin
|
||||
).apply {
|
||||
copyTypeAndValueArgumentsFrom(expression, receiversAsArguments = true)
|
||||
copyFromWithPlaceholderTypeArguments(expression, context.irBuiltIns)
|
||||
copyAttributes(expression)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ import org.jetbrains.kotlin.ir.symbols.*
|
||||
|
||||
interface IrCallableReference : IrMemberAccessExpression
|
||||
|
||||
interface IrFunctionReference : IrCallableReference {
|
||||
override val symbol: IrFunctionSymbol
|
||||
interface IrFunctionReference : IrCallableReference, IrFunctionAccessExpression {
|
||||
val reflectionTarget: IrFunctionSymbol?
|
||||
}
|
||||
|
||||
@@ -43,4 +42,4 @@ interface IrLocalDelegatedPropertyReference : IrCallableReference {
|
||||
val delegate: IrVariableSymbol
|
||||
val getter: IrSimpleFunctionSymbol
|
||||
val setter: IrSimpleFunctionSymbol?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
@@ -555,35 +554,9 @@ fun IrFunctionAccessExpression.copyTypeAndValueArgumentsFrom(
|
||||
src: IrFunctionAccessExpression,
|
||||
receiversAsArguments: Boolean = false,
|
||||
argumentsAsReceivers: Boolean = false
|
||||
) = copyTypeAndValueArgumentsFrom(
|
||||
src,
|
||||
src.symbol.owner,
|
||||
symbol.owner,
|
||||
receiversAsArguments,
|
||||
argumentsAsReceivers
|
||||
)
|
||||
|
||||
fun IrFunctionReference.copyTypeAndValueArgumentsFrom(
|
||||
src: IrFunctionReference,
|
||||
receiversAsArguments: Boolean = false,
|
||||
argumentsAsReceivers: Boolean = false
|
||||
) = copyTypeAndValueArgumentsFrom(
|
||||
src,
|
||||
src.symbol.owner,
|
||||
symbol.owner,
|
||||
receiversAsArguments,
|
||||
argumentsAsReceivers
|
||||
)
|
||||
|
||||
private fun IrMemberAccessExpression.copyTypeAndValueArgumentsFrom(
|
||||
src: IrMemberAccessExpression,
|
||||
srcFunction: IrFunction,
|
||||
destFunction: IrFunction,
|
||||
receiversAsArguments: Boolean = false,
|
||||
argumentsAsReceivers: Boolean = false
|
||||
) {
|
||||
copyTypeArgumentsFrom(src)
|
||||
copyValueArgumentsFrom(src, srcFunction, destFunction, receiversAsArguments, argumentsAsReceivers)
|
||||
copyValueArgumentsFrom(src, src.symbol.owner, symbol.owner, receiversAsArguments, argumentsAsReceivers)
|
||||
}
|
||||
|
||||
fun IrMemberAccessExpression.copyValueArgumentsFrom(
|
||||
|
||||
Reference in New Issue
Block a user