Fix for KT-7999: Wrong result when use nullable types as reified parameter, KT-8043: Unsafe cast to reified parameter throws NPE instead of TypeCastException

#KT-7999 Fixed
  #KT-8043 Fixed

~
This commit is contained in:
Michael Bogdanov
2015-11-28 12:32:11 +03:00
parent 3478a6fb6c
commit 4b8017e34b
37 changed files with 756 additions and 40 deletions
@@ -0,0 +1,45 @@
import test.*
fun box(): String {
if (null.foo<Any>() != null) return "failTypeCast 1"
if (null.foo<Any?>() != null) return "failTypeCast 2"
if (null.foo<A>() != null) return "failTypeCast 3"
if (null.foo<A?>() != null) return "failTypeCast 4"
val a = A()
if (a.foo<Any>() != a) return "failTypeCast 5"
if (a.foo<Any?>() != a) return "failTypeCast 6"
if (a.foo<A>() != a) return "failTypeCast 7"
if (a.foo<A?>() != a) return "failTypeCast 8"
val b = B()
failClassCast { b.foo<A>(); return "failTypeCast 9" }
failClassCast { b.foo<A?>(); return "failTypeCast 10" }
return "OK"
}
inline fun failTypeCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
}
}
inline fun failClassCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
throw e
}
catch (e: ClassCastException) {
}
}