Tests for recently fixed bugs

This commit is contained in:
Andrey Breslav
2011-11-29 22:11:42 +03:00
parent 8a93421ecb
commit dd4cc1686d
3 changed files with 27 additions and 0 deletions
@@ -0,0 +1,8 @@
// KT-174 Nullability info for extension function receivers
// +JDK
trait Tree {}
fun Any?.TreeValue() : Tree {
if (this is Tree) return this
throw Exception()
}
@@ -0,0 +1,9 @@
// KT-201 Allow to call extension with nullable receiver with a '.'
// +JDK
fun <T : Any> T?.npe() : T = if (this == null) throw NullPointerException() else this
fun foo() {
val i : Int? = 1
i.npe() // error!
}
@@ -0,0 +1,10 @@
// KT-312 Nullability problem when a nullable version of a generic type is returned
fun <T> Array<out T>.safeGet(index : Int) : T? {
return if (index < size) this[index] else null
}
val args : Array<String> = Array<String>(1)
val name : String = <!TYPE_MISMATCH!>args.safeGet<String>(0)<!> // No error, must be type mismatch
val name1 : String? = args.safeGet(0)