From bedac19b999c020b3b729f5be055c114863e9767 Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Mon, 30 Oct 2023 18:56:15 +0100 Subject: [PATCH] [JVM] Rewrite `isCallInsideSameModuleAsCallee` Try to use `IrModuleFragment` instead of `ModuleDescriptor`. This change is required for the evaluate expression in IDE. When we compile some code fragment with inline function call that has an anonymous object in callee, we will get incorrect behavior. Code fragment is wrapped in `EvaluatorModuleDescriptor` and we accidentally think that inline call and callee are in different modules that leads to an error in `AnonymousObjectTransformer.doTransform`. #KT-63454 Fixed --- .../jvm/codegen/IrSourceCompilerForInline.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt index e01809d2c5f..d0ba363a7b9 100644 --- a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt +++ b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt @@ -106,7 +106,25 @@ class IrSourceCompilerForInline( @OptIn(ObsoleteDescriptorBasedAPI::class) override val isCallInsideSameModuleAsCallee: Boolean - get() = callee.module == codegen.irFunction.module + get() { + val inlineFunModule = callee.fileOrNull?.module + val currentlyGeneratedFunModule = codegen.irFunction.fileOrNull?.module + check(currentlyGeneratedFunModule != null) { + "There is no module for function ${codegen.irFunction.name}:\n${codegen.irFunction.render()}" + } + + return if (inlineFunModule == null) { + callee.module == codegen.irFunction.module + } else { + // Check by IR is needed for the evaluate expression in IDE. + // When we compile some code fragment with inline function call + // that has an anonymous object in callee, we will get incorrect behavior. + // Code fragment is wrapped in `EvaluatorModuleDescriptor` and we accidentally + // think that inline call and callee are in different modules that leads to an error in + // `AnonymousObjectTransformer.doTransform`. + inlineFunModule == currentlyGeneratedFunModule + } + } override val isFinallyMarkerRequired: Boolean get() = codegen.isFinallyMarkerRequired