JS backend: fixed wrong NPE when casting to generic type.

This commit is contained in:
Zalim Bashorov
2014-06-23 20:10:35 +04:00
parent 0d0751c3f9
commit 444932d4c1
3 changed files with 84 additions and 3 deletions
@@ -0,0 +1,74 @@
package foo
class A(val s: String)
fun castsNotNullToNullableT<T>(a: Any) {
a as T
a as T?
a as? T
a as? T?
}
fun castsNullableToNullableT<T>(a: Any?) {
a as T
a as T?
a as? T
a as? T?
}
fun castsNotNullToNotNullT<T : Any>(a: Any) {
a as T
a as T?
a as? T
a as? T?
}
fun castNullableToNotNullT<T : Any>(a: Any?) {
a as T
}
fun castsNullableToNotNullT<T : Any>(a: Any?) {
a as T?
a as? T
a as? T?
}
fun test(f: () -> Unit) {
try {
f()
}
catch(e: Exception) {
throw Exception("Failed in $f with unexpected exception $e")
}
}
fun fails(f: () -> Unit) {
try {
f()
}
catch(e: Exception) {
return
}
throw Exception("Expected an exception to be thrown from $f")
}
fun box(): String {
val a = A("OK")
test { castsNotNullToNullableT<A>(a) }
test { castsNullableToNullableT<A>(a) }
test { castsNullableToNullableT<A>(null) }
test { castsNotNullToNotNullT<A>(a) }
test { castsNullableToNotNullT<A>(a) }
test { castsNullableToNotNullT<A>(null) }
test { castNullableToNotNullT<A>(a) }
fails { castNullableToNotNullT<A>(null) }
return "OK"
}