blob: aad2f8202029bab1a06d1143eb3ae70e50a20d25 [file]
// RUN_PIPELINE_TILL: FRONTEND
// WITH_STDLIB
// ISSUE: KT-59669
import kotlin.contracts.*
@OptIn(ExperimentalContracts::class)
inline fun <T> run2(x: () -> T, y: () -> T) {
contract {
callsInPlace(x, InvocationKind.EXACTLY_ONCE)
callsInPlace(y, InvocationKind.EXACTLY_ONCE)
}
x()
y()
}
fun test1() {
val x: Int
run2({ x = 1 }, { <!VAL_REASSIGNMENT!>x<!> = 2 })
x.inc()
}
fun test2() {
val x: Int
run2({ x = 1 }, {})
run2({}, { <!VAL_REASSIGNMENT!>x<!> = 2 })
x.inc()
}
fun test3(p: Boolean) {
val x: Int
run2(
{
if (p) {
x = 1
} else {
x = 2
}
},
{ <!VAL_REASSIGNMENT!>x<!> = 3 }
)
x.inc()
}
class C {
val x: Int
init {
C().apply {
run2({ <!VAL_REASSIGNMENT!>x<!> = 1 }, { <!VAL_REASSIGNMENT!>x<!> = 1 })
}
run2({ x = 1 }, { <!VAL_REASSIGNMENT!>x<!> = 2 })
x.inc()
}
}
/* GENERATED_FIR_TAGS: assignment, classDeclaration, classReference, contractCallsEffect, contracts, functionDeclaration,
functionalType, ifExpression, init, inline, integerLiteral, lambdaLiteral, localProperty, nullableType,
propertyDeclaration, typeParameter */