TEST: tests for instanceof are modified to take in account null and nullable
This commit is contained in:
committed by
vvlevchenko
parent
6331323ef1
commit
3eec3da511
@@ -252,7 +252,8 @@ task objectBasic(type: UnitKonanTest) {
|
|||||||
source = "codegen/klass/basic.kt"
|
source = "codegen/klass/basic.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
task check_type(type: UnitKonanTest) {
|
task check_type(type: RunKonanTest) {
|
||||||
|
goldValue = "true\nfalse\ntrue\ntrue\ntrue\ntrue\n"
|
||||||
source = "codegen/basics/check_type.kt"
|
source = "codegen/basics/check_type.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ class B() {}
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
//-----------------------------------------------------------------------------//
|
||||||
|
|
||||||
fun isTypeOf(a: Any) : Boolean {
|
fun isTypeOf(a: Any?) : Boolean {
|
||||||
return a is A
|
return a is A
|
||||||
}
|
}
|
||||||
|
|
||||||
fun check_type(): Boolean {
|
//-----------------------------------------------------------------------------//
|
||||||
val a = A()
|
|
||||||
return isTypeOf(a)
|
fun isTypeNullableOf(a: Any?) : Boolean {
|
||||||
|
return a is A?
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
//-----------------------------------------------------------------------------//
|
||||||
@@ -19,34 +20,20 @@ fun isNotTypeOf(a: Any) : Boolean {
|
|||||||
return a !is A
|
return a !is A
|
||||||
}
|
}
|
||||||
|
|
||||||
fun check_not_type(): Boolean {
|
|
||||||
val b = B()
|
|
||||||
return isNotTypeOf(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
//-----------------------------------------------------------------------------//
|
||||||
|
|
||||||
fun isTypeOfInterface(a: Any) : Boolean {
|
fun isTypeOfInterface(a: Any) : Boolean {
|
||||||
return a is I
|
return a is I
|
||||||
}
|
}
|
||||||
|
|
||||||
fun check_interface(): Boolean {
|
//-----------------------------------------------------------------------------//
|
||||||
val a = A()
|
|
||||||
return isTypeOfInterface(a)
|
|
||||||
}
|
|
||||||
|
|
||||||
//interface AI {
|
fun main(args: Array<String>) {
|
||||||
// fun v():Int
|
|
||||||
//}
|
println(isTypeOf(A()))
|
||||||
//
|
println(isTypeOf(null))
|
||||||
//val global:Int = 1
|
println(isTypeNullableOf(A()))
|
||||||
//class A1() : AI {
|
println(isTypeNullableOf(null))
|
||||||
// override fun v():Int = global
|
println(isNotTypeOf(B()))
|
||||||
//}
|
println(isTypeOfInterface(A()))
|
||||||
//
|
}
|
||||||
//fun smartCast(a:Any): Int {
|
|
||||||
// if (a is AI) {
|
|
||||||
// return a.v()
|
|
||||||
// }
|
|
||||||
// return 24
|
|
||||||
//}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user