[Tests] Test samples from KEEP
This commit is contained in:
committed by
TeamCityServer
parent
b0a7be72e8
commit
d8faa9686d
+33
@@ -0,0 +1,33 @@
|
||||
// FIR_IDENTICAL
|
||||
class File(name: String)
|
||||
interface InputStream
|
||||
|
||||
interface AutoCloseScope {
|
||||
fun defer(closeBlock: () -> Unit)
|
||||
fun close()
|
||||
}
|
||||
class AutoCloseScopeImpl : AutoCloseScope {
|
||||
override fun defer(closeBlock: () -> Unit) = TODO()
|
||||
override fun close() = TODO()
|
||||
}
|
||||
|
||||
context(AutoCloseScope)
|
||||
fun File.open(): InputStream = TODO()
|
||||
|
||||
fun withAutoClose(block: context(AutoCloseScope) () -> Unit) {
|
||||
val scope = AutoCloseScopeImpl() // Not shown here
|
||||
try {
|
||||
with(scope) { block() }
|
||||
} finally {
|
||||
scope.close()
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
withAutoClose {
|
||||
val input = File("input.txt").open()
|
||||
val config = File("config.txt").open()
|
||||
// Work
|
||||
// All files are closed at the end
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user