Relax type parameter constraint for Closeable.use and AutoCloseable.use to allow nullable receiver.
#KT-12894 Fixed
This commit is contained in:
@@ -152,17 +152,17 @@ public fun URL.readBytes(): ByteArray = openStream().use { it.readBytes() }
|
||||
* @return the result of [block] function on this closable resource.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T : Closeable, R> T.use(block: (T) -> R): R {
|
||||
public inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
|
||||
var closed = false
|
||||
try {
|
||||
return block(this)
|
||||
} catch (e: Throwable) {
|
||||
closed = true
|
||||
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
|
||||
platformCloseSuppressed(this, e)
|
||||
if (this != null) platformCloseSuppressed(this, e)
|
||||
throw e
|
||||
} finally {
|
||||
if (!closed) {
|
||||
if (this != null && !closed) {
|
||||
close()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user