[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
This commit is contained in:
Ivan Kylchik
2023-10-30 18:56:15 +01:00
committed by Space Team
parent 5cd3f8bb97
commit bedac19b99
@@ -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