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:
+54
@@ -0,0 +1,54 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +ReadDeserializedContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// IGNORE_BACKEND: JVM_IR, NATIVE
|
||||
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
|
||||
// NO_CHECK_LAMBDA_INLINING
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
interface SomeOutputScreenCallbacks {
|
||||
fun ontest()
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
class OutputWorkScreenView(callbacks: SomeOutputScreenCallbacks) {
|
||||
val root = vBox {
|
||||
button(callbacks::ontest)
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
inline fun vBox(
|
||||
crossinline action: () -> Unit
|
||||
) {
|
||||
contract {
|
||||
callsInPlace(action, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return { action() }()
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
inline fun button(
|
||||
onAction: () -> Unit
|
||||
) {
|
||||
onAction()
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
import kotlin.contracts.*
|
||||
|
||||
@ExperimentalContracts
|
||||
fun box(): String {
|
||||
var res = "FAIL"
|
||||
OutputWorkScreenView(object : SomeOutputScreenCallbacks {
|
||||
override fun ontest() {
|
||||
res = "OK"
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user