JS/RTTI: cast to generic type parameter as to Any

This commit is contained in:
Alexey Tsvetkov
2015-06-17 16:19:58 +03:00
committed by Alexey Andreev
parent 38b0effe15
commit 7cfe1433c5
2 changed files with 35 additions and 42 deletions
@@ -34,30 +34,16 @@ fun <T : Any> castsNullableToNotNullT(a: Any?) {
a as? T?
}
fun test(f: () -> Unit) {
try {
f()
}
catch(e: Exception) {
throw Exception("Failed in $f with unexpected exception $e")
}
}
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) }
castsNotNullToNullableT<A>(a)
castsNullableToNullableT<A>(a)
castsNullableToNullableT<A>(null)
castsNotNullToNotNullT<A>(a)
castsNullableToNotNullT<A>(a)
castsNullableToNotNullT<A>(null)
castNullableToNotNullT<A>(a)
failsClassCast("castNullableToNotNullT<A>(null)") { castNullableToNotNullT<A>(null) }
return "OK"