Cast dispatch receiver to actual declaration owner though inline
Otherwise corrupted frame information is generated in bytecode #KT-29242 Fixed
This commit is contained in:
@@ -2655,7 +2655,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
return new InlineCodegenForDefaultBody(functionDescriptor, this, state, methodOwner, signature, sourceCompiler);
|
||||
}
|
||||
else {
|
||||
return new PsiInlineCodegen(this, state, functionDescriptor, methodOwner, signature, typeParameterMappings, sourceCompiler);
|
||||
return new PsiInlineCodegen(this, state, functionDescriptor, methodOwner, signature, typeParameterMappings, sourceCompiler,
|
||||
typeMapper.mapOwner(descriptor));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
||||
protected val codegen: T,
|
||||
protected val state: GenerationState,
|
||||
protected val functionDescriptor: FunctionDescriptor,
|
||||
private val methodOwner: Type,
|
||||
protected val methodOwner: Type,
|
||||
protected val jvmSignature: JvmMethodSignature,
|
||||
private val typeParameterMappings: TypeParameterMappings<*>,
|
||||
protected val sourceCompiler: SourceCompilerForInline,
|
||||
@@ -427,7 +427,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
||||
val type = info.type
|
||||
val local = StackValue.local(index[i], type)
|
||||
if (!skipStore) {
|
||||
local.store(StackValue.onStack(type), codegen.v)
|
||||
local.store(StackValue.onStack(info.typeOnStack), codegen.v)
|
||||
}
|
||||
if (info is CapturedParamInfo) {
|
||||
info.remapValue = local
|
||||
|
||||
@@ -24,7 +24,8 @@ open class ParameterInfo(
|
||||
val isSkipped: Boolean, //for skipped parameter: e.g. inlined lambda
|
||||
val index: Int,
|
||||
var remapValue: StackValue?, //in case when parameter could be extracted from outer context (e.g. from local var)
|
||||
val declarationIndex: Int
|
||||
val declarationIndex: Int,
|
||||
val typeOnStack: Type = type
|
||||
) {
|
||||
|
||||
var isCaptured: Boolean = false
|
||||
|
||||
@@ -23,8 +23,8 @@ class ParametersBuilder private constructor() {
|
||||
return addParameter(ParameterInfo(type, skipped, nextParameterOffset, -1, nextValueParameterIndex))
|
||||
}
|
||||
|
||||
fun addNextParameter(type: Type, skipped: Boolean): ParameterInfo {
|
||||
return addParameter(ParameterInfo(type, skipped, nextParameterOffset, null, nextValueParameterIndex))
|
||||
fun addNextParameter(type: Type, skipped: Boolean, typeOnStack: Type = type): ParameterInfo {
|
||||
return addParameter(ParameterInfo(type, skipped, nextParameterOffset, null, nextValueParameterIndex, typeOnStack))
|
||||
}
|
||||
|
||||
fun addNextValueParameter(type: Type, skipped: Boolean, remapValue: StackValue?, parameterIndex: Int): ParameterInfo {
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCallWithAssert
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil.isInlinableParameterExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
@@ -36,7 +35,8 @@ class PsiInlineCodegen(
|
||||
methodOwner: Type,
|
||||
signature: JvmMethodSignature,
|
||||
typeParameterMappings: TypeParameterMappings<KotlinType>,
|
||||
sourceCompiler: SourceCompilerForInline
|
||||
sourceCompiler: SourceCompilerForInline,
|
||||
private val actualDispatchReceiver: Type = methodOwner
|
||||
) : InlineCodegen<ExpressionCodegen>(
|
||||
codegen, state, function, methodOwner, signature, typeParameterMappings, sourceCompiler,
|
||||
ReifiedTypeInliner(typeParameterMappings, object : ReifiedTypeInliner.IntrinsicsSupport<KotlinType> {
|
||||
@@ -73,7 +73,7 @@ class PsiInlineCodegen(
|
||||
|
||||
override fun processAndPutHiddenParameters(justProcess: Boolean) {
|
||||
if (getMethodAsmFlags(functionDescriptor, sourceCompiler.contextKind, state) and Opcodes.ACC_STATIC == 0) {
|
||||
invocationParamBuilder.addNextParameter(AsmTypes.OBJECT_TYPE, false)
|
||||
invocationParamBuilder.addNextParameter(methodOwner, false, actualDispatchReceiver)
|
||||
}
|
||||
|
||||
for (param in jvmSignature.valueParameters) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// See also kt33054.kt
|
||||
|
||||
|
||||
Reference in New Issue
Block a user