fixes bugs in TypeInfo

This commit is contained in:
Alex Tkachman
2011-09-01 14:01:05 +02:00
parent 9e9959f953
commit 475b15aaca
4 changed files with 96 additions and 18 deletions
+52 -6
View File
@@ -1,20 +1,66 @@
class A() {}
class B<T>() {}
class B<T>() {
fun isT (a : Any?) : Boolean {
return a is T
}
}
fun box() : String {
fun t1() : Boolean {
val a = A()
System.out?.println(a is A) //true
System.out?.println(a is A?) //true
if(a !is A) return false
if(a !is A?) return false
if(null !is A?) return false
return true
}
fun t2 () : Boolean {
val b = B<String>()
System.out?.println(b is B<String>) //true
System.out?.println(b is B<String>?) //false !!!
if(b !is B<String>) return false
if(b !is B<String>?) return false
if(null !is B<String>?) return false
val v = b as B<String> //ok
val u = b as B<String>? //TypeCastException
val w : B<String>? = b as B<String> //ok
val x = w as B<String>? //TypeCastException
return true
}
fun t3 () : Boolean {
val b = B<String>()
if(!b.isT("aaa")) return false
if(b.isT(10)) return false
if(b.isT(null)) return false
val d = B<String?>()
if(!d.isT("aaa")) return false
if(d.isT(10)) return false
if(!d.isT(null)) return false
val c = B<Int>()
if(c.isT("aaa")) return false
if(!c.isT(10)) return false
if(c.isT(null)) return false
val e = B<Int?>()
if(e.isT("aaa")) return false
if(!e.isT(10)) return false
if(!e.isT(null)) return false
return true
}
fun box() : String {
if(!t1()) {
return "t1 failed"
}
if(!t2()) {
return "t2 failed"
}
if(!t3()) {
return "t3 failed"
}
return "OK"
}