Effects: add cfg-tests on inlined lambdas
========== Introduction of Effect System: 15/18
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// LANGUAGE_VERSION: 1.3
|
||||
|
||||
import kotlin.internal.contracts.*
|
||||
|
||||
inline fun <T> myRun(block: () -> T): T {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return block()
|
||||
}
|
||||
|
||||
fun someComputation(): Int = 42
|
||||
|
||||
fun tryCatchInlined() {
|
||||
val x: Int
|
||||
|
||||
myRun {
|
||||
try {
|
||||
x = someComputation()
|
||||
x.inc()
|
||||
}
|
||||
catch (e: java.lang.Exception) {
|
||||
// I?
|
||||
x.inc()
|
||||
}
|
||||
}
|
||||
|
||||
// I?
|
||||
x.inc()
|
||||
}
|
||||
|
||||
fun possibleReassignmentInTryCatch() {
|
||||
val x: Int
|
||||
|
||||
myRun {
|
||||
x = 42
|
||||
try {
|
||||
x = someComputation()
|
||||
x.inc()
|
||||
}
|
||||
catch (e: java.lang.Exception) {
|
||||
// Possible reassignment
|
||||
x = 42
|
||||
x.inc()
|
||||
}
|
||||
// Initialized
|
||||
x.inc()
|
||||
}
|
||||
// Initialized
|
||||
x.inc()
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun tryCatchOuter() {
|
||||
var x: Int
|
||||
try {
|
||||
myRun {
|
||||
x = someComputation()
|
||||
x.inc()
|
||||
}
|
||||
}
|
||||
catch (e: java.lang.UnsupportedOperationException) {
|
||||
myRun { x = 42 }
|
||||
}
|
||||
catch (e: java.lang.Exception) {
|
||||
// do nothing
|
||||
}
|
||||
// I? because we can leave with last catch-clause which doesn't initialize x
|
||||
x.inc()
|
||||
}
|
||||
Reference in New Issue
Block a user