Relax type parameter constraint for Closeable.use and AutoCloseable.use to allow nullable receiver.

#KT-12894 Fixed
This commit is contained in:
Ilya Gorbunov
2016-06-29 17:19:57 +03:00
parent e04873957e
commit 22ee3a8dc1
5 changed files with 68 additions and 6 deletions
+9
View File
@@ -141,6 +141,15 @@ class ReadWriteTest {
assertEquals(arrayListOf("Hello", "World"), list)
}
@test fun testPlatformNullUse() {
fun <T> platformNull() = java.util.Collections.singleton(null as T).first()
val resource = platformNull<java.io.Closeable>()
val result = resource.use {
"ok"
}
assertEquals("ok", result)
}
@test fun testURL() {
val url = URL("http://kotlinlang.org")
val text = url.readText()