TypeCastException when casting null to T with nullable upper-bound

#KT-3637 Fixed
This commit is contained in:
Natalia.Ukhorskaya
2013-05-20 12:13:42 +04:00
parent 1bf06f7c02
commit a5f1a8b3f8
3 changed files with 37 additions and 2 deletions
@@ -0,0 +1,21 @@
fun test1<T>() = null as T
fun test2<T>(): T {
val a : Any? = null
return a as T
}
fun test3<T: Any>() = null as T
fun box(): String {
if (test1<Int?>() != null) return "fail: test1"
if (test2<Int?>() != null) return "fail: test2"
var result3 = "fail"
try {
test3<Int>()
}
catch(e: TypeCastException) {
result3 = "OK"
}
if (result3 != "OK") return "fail: test3"
return "OK"
}