[debugger] IrFile for KtBlockCodeFragment should have a module
A module created for expression evaluation contains `fragment.kt`, the file that contains necessary code for the expression to be successfully evaluated (including the expression itself). However, the IrFileImpl created for the fragment doesn't refer to the module, leaving its lateinit `module` property uninitialized. So, simply put, a parent has a child, but that child doesn't have the parent. And that may lead to various errors. Compose has a psi2ir lowering that transforms Composable declarations, and for that it deep-copies all the declarations (see `androidx.compose.compiler.plugins.kotlin.lower. ComposerParamTransformer#lower`). During the copying, it eventually tries to access that uninitialized `module` property (`org.jetbrains.kotlin.ir.util. DeepCopyIrTreeWithSymbols.visitFile`), which predictably ends up with an exception. The exception propagates down the stack, interrupting further Compose lowerings, but eventually it gets swallowed at `com.android.tools.compose.ComposePluginIrGenerationExtension#generate`. So, fragment compilation continues and brings forth more complicated errors on later stages, in particular during the codegen, like in the IDEA-320738, when some declarations don't have their lateinit `parent`s initialized. This one example in the issue strikes during expect declarations lowering at `org.jetbrains.kotlin.backend.common.lower. ExpectDeclarationRemover.tryCopyDefaultArguments`. The problem arisen in the issue could be solved on the Compose side, but there's no telling what else can get broken because of this module-file inconsistency. Fixes IDEA-320738 Merge-request: KT-MR-10914 Merged-by: Alexander Kuznetsov <Aleksander.Kuznetsov@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
5675c19f3b
commit
c63a9582aa
+3
-3
@@ -31,7 +31,7 @@ class FragmentModuleGenerator(
|
||||
ktFiles.forEach { ktFile ->
|
||||
irModule.files.add(
|
||||
if (ktFile is KtBlockCodeFragment) {
|
||||
createEmptyIrFile(ktFile).apply {
|
||||
createEmptyIrFile(ktFile, irModule).apply {
|
||||
declarations.add(
|
||||
irDeclarationGenerator.generateClassForCodeFragment(ktFile)
|
||||
)
|
||||
@@ -61,9 +61,9 @@ class FragmentModuleGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
private fun createEmptyIrFile(ktFile: KtFile): IrFileImpl {
|
||||
private fun createEmptyIrFile(ktFile: KtFile, irModule: IrModuleFragment): IrFileImpl {
|
||||
val fileEntry = PsiIrFileEntry(ktFile)
|
||||
val packageFragmentDescriptor = context.moduleDescriptor.findPackageFragmentForFile(ktFile)!!
|
||||
return IrFileImpl(fileEntry, packageFragmentDescriptor)
|
||||
return IrFileImpl(fileEntry, packageFragmentDescriptor, irModule)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user