Do not box function argument if it is used in EXACTLY_ONCE lambda
Since we cannot change type of parameter, we cannot replace it with box type. #KT-29510 Fixed #KT-29614 Fixed #KT-29385 Fixed
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +ReadDeserializedContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
@ExperimentalContracts
|
||||
fun runOnce(action: () -> Unit) {
|
||||
contract {
|
||||
callsInPlace(action, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
action()
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
class Foo(foo: Boolean) {
|
||||
var res = "FAIL"
|
||||
init {
|
||||
runOnce {
|
||||
foo
|
||||
res = "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
fun box(): String {
|
||||
val foo = Foo(true)
|
||||
return foo.res
|
||||
}
|
||||
Reference in New Issue
Block a user