Forbid val field initialization inside EXACLTY_ONCE lambda
unless the lambda is inline. This way, final field will remain final.
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_LIGHT_ANALYSIS
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun runOnce(action: () -> Unit) {
|
||||
contract {
|
||||
callsInPlace(action, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
action()
|
||||
}
|
||||
|
||||
class Foo {
|
||||
val res: String
|
||||
init {
|
||||
runOnce {
|
||||
res = "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Foo().res
|
||||
}
|
||||
Reference in New Issue
Block a user