Add support for contract feature in inliner

This commit is contained in:
Mikhael Bogdanov
2017-12-14 17:41:49 +01:00
parent 4890979476
commit 819a3a95b3
15 changed files with 610 additions and 72 deletions
@@ -0,0 +1,29 @@
// !LANGUAGE: +CallsInPlaceEffect
// FILE: 1.kt
package test
import kotlin.internal.contracts.*
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
public inline fun <R> myrun(block: () -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return block()
}
// FILE: 2.kt
// NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
val x: Int
val res = myrun {
x = 42
{
x
}()
}
return if (res == 42 && x.inc() == 43) "OK" else "Fail: ${x.inc()}"
}