Generate is check for inline classes same as for primitives
Should be improved when inline class is based on non-null reference
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class UInt(val u: Int) {
|
||||
override fun toString(): String {
|
||||
return "UInt: $u"
|
||||
}
|
||||
}
|
||||
|
||||
fun Any.isUInt(): Boolean = this is UInt
|
||||
fun Any.notIsUInt(): Boolean = this !is UInt
|
||||
|
||||
inline fun <reified T> Any?.instanceOf(): Boolean = this is T
|
||||
|
||||
fun UInt.extension(): String = "OK:"
|
||||
|
||||
fun foo(x: UInt?): String {
|
||||
if (x is UInt) {
|
||||
return x.extension() + x.toString()
|
||||
}
|
||||
|
||||
return "fail"
|
||||
}
|
||||
|
||||
fun bar(x: UInt?): String {
|
||||
if (x is Any) {
|
||||
return x.extension()
|
||||
}
|
||||
|
||||
return "fail"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val u = UInt(12)
|
||||
if (!u.isUInt()) return "fail"
|
||||
if (u.notIsUInt()) return "fail"
|
||||
|
||||
if (1.isUInt()) return "fail"
|
||||
if (!1.notIsUInt()) return "fail"
|
||||
|
||||
|
||||
if (!u.instanceOf<UInt>()) return "fail"
|
||||
if (1.instanceOf<UInt>()) return "fail"
|
||||
|
||||
val nullableUInt: UInt? = UInt(10)
|
||||
if (!nullableUInt.instanceOf<UInt>()) return "fail"
|
||||
|
||||
val nullAsUInt: UInt? = null
|
||||
if (nullAsUInt.instanceOf<UInt>()) return "fail"
|
||||
if (!nullAsUInt.instanceOf<UInt?>()) return "fail"
|
||||
|
||||
if (foo(u) != "OK:UInt: 12") return "fail"
|
||||
if (bar(u) != "OK:") return "fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class UInt(val u: Int) {
|
||||
fun member() {}
|
||||
}
|
||||
|
||||
fun UInt?.extension() {}
|
||||
|
||||
fun test(a: Any, b: Any?) {
|
||||
if (a is UInt) {
|
||||
a.member()
|
||||
}
|
||||
|
||||
if (b is UInt?) {
|
||||
b.extension()
|
||||
}
|
||||
}
|
||||
|
||||
// 2 INSTANCEOF UInt
|
||||
// 1 CHECKCAST UInt
|
||||
|
||||
// 1 INVOKEVIRTUAL UInt.unbox
|
||||
// 2 INVOKESTATIC UInt\$Erased.member
|
||||
|
||||
// 0 intValue
|
||||
Reference in New Issue
Block a user