blob: eb7e24cae128812585e5fee01fd144cdae427cd8 [file]
// RUN_PIPELINE_TILL: FRONTEND
// DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_STDLIB
import kotlin.contracts.*
fun capture(block: () -> Unit): String = ""
@OptIn(ExperimentalContracts::class)
inline fun inPlace(block: () -> Unit): String {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
block()
return ""
}
fun consume(x: Any?) {}
class A {
val a = capture { consume(x) }
val b = inPlace {
consume(<!UNINITIALIZED_VARIABLE!>x<!>) // error
capture { consume(x) } // ok
inPlace {
consume(<!UNINITIALIZED_VARIABLE!>x<!>) // error
capture { consume(x) } // ok
}
}
val c = object {
fun foo() {
consume(x) // ok
capture { consume(x) } // ok
inPlace {
consume(x) // ok
capture { consume(x) } // ok
}
}
init {
consume(<!UNINITIALIZED_VARIABLE!>x<!>) // error
capture { consume(x) } // ok
inPlace {
consume(<!UNINITIALIZED_VARIABLE!>x<!>) // error
capture { consume(x) } // ok
}
}
val objectProp = inPlace {
consume(<!UNINITIALIZED_VARIABLE!>x<!>) // error
capture { consume(x) } // ok
inPlace {
consume(<!UNINITIALIZED_VARIABLE!>x<!>) // error
capture { consume(x) } // ok
}
}
}
val d = inPlace {
fun localFun() {
consume(x) // ok
}
capture {
localFun()
}
}
val x = 10
}
/* GENERATED_FIR_TAGS: anonymousObjectExpression, classDeclaration, classReference, contractCallsEffect, contracts,
functionDeclaration, functionalType, init, inline, integerLiteral, lambdaLiteral, localFunction, nullableType,
propertyDeclaration, stringLiteral */