mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
Minor: make tryInlined test not depend on 'Closeable.use' implementation.
This commit is contained in:
@@ -1,10 +1,21 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.io.*
|
||||
|
||||
fun test(r: Reader) {
|
||||
val ss = hashSetOf<String>()
|
||||
r.useLines { it.forEach { ss.add(it) } }
|
||||
fun test(list: List<String>) {
|
||||
val result = mutableListOf<String>()
|
||||
use1 { list.forEach { result.add(it) } }
|
||||
}
|
||||
|
||||
// 2 POP
|
||||
inline fun <T> use1(f: () -> T): T {
|
||||
return use2(f)
|
||||
}
|
||||
|
||||
inline fun <T> use2(f: () -> T): T {
|
||||
try {
|
||||
return f()
|
||||
}
|
||||
catch (e: Exception) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
// 1 POP
|
||||
|
||||
Reference in New Issue
Block a user