[JS IR] Add test on initialization calling only once
This commit is contained in:
+1
-2
@@ -284,8 +284,7 @@ private fun <T> IrDeclaration.withPersistentSafe(transform: IrDeclaration.() ->
|
|||||||
} else null
|
} else null
|
||||||
|
|
||||||
private fun IrDeclaration.isCompatibleDeclaration(context: JsIrBackendContext) =
|
private fun IrDeclaration.isCompatibleDeclaration(context: JsIrBackendContext) =
|
||||||
(this as? IrField)
|
correspondingProperty
|
||||||
?.correspondingProperty
|
|
||||||
?.hasAnnotation(context.intrinsics.jsEagerInitializationAnnotationSymbol) != true &&
|
?.hasAnnotation(context.intrinsics.jsEagerInitializationAnnotationSymbol) != true &&
|
||||||
withPersistentSafe { origin in compatibleOrigins } == true
|
withPersistentSafe { origin in compatibleOrigins } == true
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// TARGET_BACKEND: JS_IR
|
||||||
|
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||||
|
// PROPERTY_LAZY_INITIALIZATION
|
||||||
|
|
||||||
|
// FILE: lib.kt
|
||||||
|
var z1 = false
|
||||||
|
|
||||||
|
// FILE: lib2.kt
|
||||||
|
|
||||||
|
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||||
|
@JsEagerInitialization
|
||||||
|
val x = run { z1 = !z1; 42 }
|
||||||
|
|
||||||
|
val y = run { 73 }
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return if (z1) "OK" else "fail"
|
||||||
|
}
|
||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -19852,6 +19852,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/properties/eagerInitializationGlobal2.kt");
|
runTest("compiler/testData/codegen/box/properties/eagerInitializationGlobal2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("eagerInitializationGlobal3.kt")
|
||||||
|
public void testEagerInitializationGlobal3() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/properties/eagerInitializationGlobal3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("field.kt")
|
@TestMetadata("field.kt")
|
||||||
public void testField() throws Exception {
|
public void testField() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/field.kt");
|
runTest("compiler/testData/codegen/box/properties/field.kt");
|
||||||
|
|||||||
Generated
+5
@@ -19258,6 +19258,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/properties/eagerInitializationGlobal2.kt");
|
runTest("compiler/testData/codegen/box/properties/eagerInitializationGlobal2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("eagerInitializationGlobal3.kt")
|
||||||
|
public void testEagerInitializationGlobal3() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/properties/eagerInitializationGlobal3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("field.kt")
|
@TestMetadata("field.kt")
|
||||||
public void testField() throws Exception {
|
public void testField() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/field.kt");
|
runTest("compiler/testData/codegen/box/properties/field.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user