Files
kotlin-fork/compiler/testData/diagnostics/tests/controlFlowAnalysis/capturingUninitializedVariableInNonInPlaceLambda.kt
T
Dmitrii Gridin 9a4a3d1f49 [LL FIR] introduce test with reversed resolve order
^KT-56543

Merge-request: KT-MR-9299
Merged-by: Dmitrii Gridin <dmitry.gridin@jetbrains.com>
2023-03-22 17:34:07 +00:00

73 lines
1.5 KiB
Kotlin
Vendored

// IGNORE_REVERSED_RESOLVE
// DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_STDLIB
import kotlin.contracts.*
fun capture(block: () -> Unit): String = ""
@OptIn(ExperimentalContracts::class)
inline fun inPlace(block: () -> Unit): String {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
block()
return ""
}
fun consume(x: Any?) {}
class A {
val a = capture { consume(x) }
val b = inPlace {
consume(x) // error
capture { consume(x) } // ok
inPlace {
consume(x) // error
capture { consume(x) } // ok
}
}
val c = object {
fun foo() {
consume(x) // ok
capture { consume(x) } // ok
inPlace {
consume(x) // ok
capture { consume(x) } // ok
}
}
init {
consume(<!UNINITIALIZED_VARIABLE!>x<!>) // error
capture { consume(x) } // ok
inPlace {
consume(x) // error
capture { consume(x) } // ok
}
}
val objectProp = inPlace {
consume(x) // error
capture { consume(x) } // ok
inPlace {
consume(x) // error
capture { consume(x) } // ok
}
}
}
val d = inPlace {
fun localFun() {
consume(x) // ok
}
capture {
localFun()
}
}
val x = 10
}