[JS IR] Add initialisation call for functions in method
^KT-43222 fixed
This commit is contained in:
+13
-11
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.ir.backend.js.utils.isPure
|
|||||||
import org.jetbrains.kotlin.ir.builders.declarations.addFunction
|
import org.jetbrains.kotlin.ir.builders.declarations.addFunction
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildField
|
import org.jetbrains.kotlin.ir.builders.declarations.buildField
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrElementBase
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.DeclarationCarrier
|
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.DeclarationCarrier
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -42,14 +41,12 @@ class PropertyLazyInitLowering(
|
|||||||
get() = context.fileToInitialisationFuns
|
get() = context.fileToInitialisationFuns
|
||||||
|
|
||||||
override fun lower(irBody: IrBody, container: IrDeclaration) {
|
override fun lower(irBody: IrBody, container: IrDeclaration) {
|
||||||
val property = container.correspondingProperty ?: return
|
if (container !is IrSimpleFunction && container !is IrField && container !is IrProperty)
|
||||||
|
return
|
||||||
|
|
||||||
val topLevelProperty = property
|
if (!container.isTopLevel) return
|
||||||
.takeIf { it.isForLazyInit() }
|
|
||||||
?.takeIf { it.backingField?.initializer != null }
|
|
||||||
?: return
|
|
||||||
|
|
||||||
val file = topLevelProperty.parent as? IrFile
|
val file = container.parent as? IrFile
|
||||||
?: return
|
?: return
|
||||||
|
|
||||||
val initFun = fileToInitialisationFuns[file]
|
val initFun = fileToInitialisationFuns[file]
|
||||||
@@ -65,10 +62,13 @@ class PropertyLazyInitLowering(
|
|||||||
is IrSimpleFunction ->
|
is IrSimpleFunction ->
|
||||||
irBody.addInitialisation(initialisationCall, container)
|
irBody.addInitialisation(initialisationCall, container)
|
||||||
is IrField -> {
|
is IrField -> {
|
||||||
property
|
container
|
||||||
.let { listOf(it.getter, it.setter) }
|
.correspondingProperty
|
||||||
.filterNotNull()
|
?.takeIf { it.isForLazyInit() }
|
||||||
.forEach {
|
?.takeIf { it.backingField?.initializer != null }
|
||||||
|
?.let { listOf(it.getter, it.setter) }
|
||||||
|
?.filterNotNull()
|
||||||
|
?.forEach {
|
||||||
irBody.addInitialisation(initialisationCall, it)
|
irBody.addInitialisation(initialisationCall, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,6 +86,8 @@ class PropertyLazyInitLowering(
|
|||||||
declarations
|
declarations
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (fieldToInitializer.isEmpty()) return null
|
||||||
|
|
||||||
// if (allFieldsInFilePure(fieldToInitializer.values)) {
|
// if (allFieldsInFilePure(fieldToInitializer.values)) {
|
||||||
// return null
|
// return null
|
||||||
// }
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user