diff --git a/compiler/testData/diagnostics/tests/script/topLevelPropertyInitialization.ll.kts b/compiler/testData/diagnostics/tests/script/topLevelPropertyInitialization.ll.kts new file mode 100644 index 00000000000..d5e9d3c8432 --- /dev/null +++ b/compiler/testData/diagnostics/tests/script/topLevelPropertyInitialization.ll.kts @@ -0,0 +1,61 @@ +// LL_FIR_DIVERGENCE +// KT-64074 +// LL_FIR_DIVERGENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -WRONG_INVOCATION_KIND +// WITH_STDLIB + +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract +import kotlin.properties.ReadOnlyProperty + +@OptIn(ExperimentalContracts::class) +inline fun inPlaceRun(block: () -> T): T { + contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } + return block() +} + +fun notInPlaceRun(block: () -> T): T = null!! + +fun simpleDelegate(value: T): ReadOnlyProperty = null!! + +@OptIn(ExperimentalContracts::class) +fun inPlaceDelegate(block: () -> T): ReadOnlyProperty { + contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } + return null!! +} + +fun notInPlaceDelegate(block: () -> T): ReadOnlyProperty = null!! + +val a: String = a +val b: String = inPlaceRun { b } +val c: String = notInPlaceRun { c } + +val d: String by simpleDelegate(d) +val e: String by inPlaceDelegate { e } +val f: String by notInPlaceDelegate { f } + +val g: Int +val h = 1.also { g = 2 } +val i: Int +val j by lazy { i = 2; 1 } +val k: Int + get() { + i = 3 + return i + } + +val l: Comparator = object : Comparator { + val delegate: Comparator get() = n + override fun compare(o1: String, o2: String): Int = delegate.compare(o1, o2) +} +val m: Comparator = object : Comparator by n {} +val n: Comparator = Comparator { _, _ -> 0 } + +val t: String = z +val u: String = inPlaceRun { z } +val v: String = notInPlaceRun { z } +val w: String by simpleDelegate(z) +val x: String by inPlaceDelegate { z } +val y: String by notInPlaceDelegate { z } +val z: String = "VALUE"