Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/variables/capturedByNested.fir.kt
T
2023-08-18 13:29:20 +00:00

22 lines
451 B
Kotlin
Vendored

import kotlin.contracts.*
@Suppress(<!ERROR_SUPPRESSION!>"OPT_IN_USAGE_ERROR"<!>, "OPT_IN_USAGE_FUTURE_ERROR")
fun exactlyOnce(f: () -> Unit) {
contract {
callsInPlace(f, InvocationKind.EXACTLY_ONCE)
}
f()
}
fun test() {
var s: String? = ""
if (s != null) {
val block: () -> Unit
exactlyOnce {
block = { s = null }
}
block()
<!SMARTCAST_IMPOSSIBLE!>s<!>.length
}
}