Add contract for 'use'
#KT-35216 Fixed
This commit is contained in:
committed by
Ilya Gorbunov
parent
043eddb432
commit
941de655c4
@@ -19,6 +19,8 @@
|
||||
@file:kotlin.jvm.JvmPackageName("kotlin.jdk7")
|
||||
package kotlin
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
/**
|
||||
* Executes the given [block] function on this resource and then closes it down correctly whether an exception
|
||||
* is thrown or not.
|
||||
@@ -32,6 +34,9 @@ package kotlin
|
||||
@SinceKotlin("1.2")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T : AutoCloseable?, R> T.use(block: (T) -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
var exception: Throwable? = null
|
||||
try {
|
||||
return block(this)
|
||||
|
||||
Reference in New Issue
Block a user