[JS IR] Assert createdOn equals 0 for properties initialization fun for file
This commit is contained in:
+12
-2
@@ -50,11 +50,13 @@ class PropertyLazyInitLowering(
|
|||||||
if (container !is IrField && container !is IrSimpleFunction && container !is IrProperty)
|
if (container !is IrField && container !is IrSimpleFunction && container !is IrProperty)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (container.origin !in compatibleOrigins) return
|
if (!container.isCompatibleDeclaration()) return
|
||||||
|
|
||||||
val file = container.parent as? IrFile
|
val file = container.parent as? IrFile
|
||||||
?: return
|
?: return
|
||||||
|
|
||||||
|
container.assertCompatibleDeclaration()
|
||||||
|
|
||||||
val initFun = (when {
|
val initFun = (when {
|
||||||
file in fileToInitializationFuns -> fileToInitializationFuns[file]
|
file in fileToInitializationFuns -> fileToInitializationFuns[file]
|
||||||
fileToInitializerPureness[file] == true -> null
|
fileToInitializerPureness[file] == true -> null
|
||||||
@@ -242,7 +244,10 @@ class RemoveInitializersForLazyProperties(
|
|||||||
declaration.correspondingProperty
|
declaration.correspondingProperty
|
||||||
?.takeIf { it.isForLazyInit() }
|
?.takeIf { it.isForLazyInit() }
|
||||||
?.backingField
|
?.backingField
|
||||||
?.let { it.initializer = null }
|
?.let {
|
||||||
|
it.assertCompatibleDeclaration()
|
||||||
|
it.initializer = null
|
||||||
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -298,9 +303,14 @@ private fun IrDeclaration.propertyWithPersistentSafe(transform: IrDeclaration.()
|
|||||||
private fun IrDeclaration.isCompatibleDeclaration() =
|
private fun IrDeclaration.isCompatibleDeclaration() =
|
||||||
origin in compatibleOrigins
|
origin in compatibleOrigins
|
||||||
|
|
||||||
|
private fun IrDeclaration.assertCompatibleDeclaration() {
|
||||||
|
assert((this as? PersistentIrElementBase<*>)?.createdOn?.let { it == 0 } != false)
|
||||||
|
}
|
||||||
|
|
||||||
private val compatibleOrigins = listOf(
|
private val compatibleOrigins = listOf(
|
||||||
IrDeclarationOrigin.DEFINED,
|
IrDeclarationOrigin.DEFINED,
|
||||||
IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
|
IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
|
||||||
|
IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||||
IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR,
|
IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR,
|
||||||
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
|
IrDeclarationOrigin.PROPERTY_BACKING_FIELD,
|
||||||
)
|
)
|
||||||
+5
@@ -1,12 +1,17 @@
|
|||||||
// TARGET_BACKEND: JS_IR
|
// TARGET_BACKEND: JS_IR
|
||||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||||
// PROPERTY_LAZY_INITIALIZATION
|
// PROPERTY_LAZY_INITIALIZATION
|
||||||
|
// KJS_WITH_FULL_RUNTIME
|
||||||
|
|
||||||
// FILE: A.kt
|
// FILE: A.kt
|
||||||
val a1 = "a".let {
|
val a1 = "a".let {
|
||||||
it + "a"
|
it + "a"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val b1 by lazy {
|
||||||
|
"b1"
|
||||||
|
}
|
||||||
|
|
||||||
object A {
|
object A {
|
||||||
private val foo = "foo"
|
private val foo = "foo"
|
||||||
val foo2 = foo
|
val foo2 = foo
|
||||||
|
|||||||
Reference in New Issue
Block a user