JS/RTTI: if it's known that T <: X & Y, where T is non-reified type variable, for each a is T check that a is X && a is Y
This commit is contained in:
Vendored
+59
@@ -0,0 +1,59 @@
|
||||
package foo
|
||||
|
||||
open class A()
|
||||
|
||||
interface X
|
||||
|
||||
interface Y
|
||||
|
||||
class B() : A(), X, Y {
|
||||
override fun toString() = "B"
|
||||
}
|
||||
|
||||
class C() : A(), X, Y {
|
||||
override fun toString() = "C"
|
||||
}
|
||||
|
||||
class D() : A() {
|
||||
override fun toString() = "D"
|
||||
}
|
||||
|
||||
class E() : X {
|
||||
override fun toString() = "E"
|
||||
}
|
||||
|
||||
class F() : A(), Y {
|
||||
override fun toString() = "E"
|
||||
}
|
||||
|
||||
fun <T> test(a: Any): String where T : A, T : X, T : Y {
|
||||
return (try {
|
||||
a as T
|
||||
}
|
||||
catch (e: Exception) {
|
||||
"error"
|
||||
}).toString()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
val c = C()
|
||||
val d = D()
|
||||
val e = E()
|
||||
val f = F()
|
||||
|
||||
assertEquals("B", test<B>(b))
|
||||
assertEquals("B", test<C>(b))
|
||||
|
||||
assertEquals("C", test<B>(c))
|
||||
assertEquals("C", test<C>(c))
|
||||
|
||||
assertEquals("error", test<B>(d))
|
||||
assertEquals("error", test<C>(d))
|
||||
assertEquals("error", test<B>(e))
|
||||
assertEquals("error", test<C>(e))
|
||||
assertEquals("error", test<B>(f))
|
||||
assertEquals("error", test<C>(f))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package foo
|
||||
|
||||
// CHECK_METHOD_NOT_CALLED_IN_SCOPE: scope=box function=isType
|
||||
// CHECK_NOT_CALLED_IN_SCOPE: scope=box function=isType
|
||||
|
||||
open class A()
|
||||
|
||||
|
||||
@@ -560,6 +560,12 @@ var Kotlin = {};
|
||||
return object != null;
|
||||
}
|
||||
};
|
||||
|
||||
Kotlin.andPredicate = function (a, b) {
|
||||
return function (object) {
|
||||
return a(object) && b(object);
|
||||
}
|
||||
};
|
||||
|
||||
Kotlin.kotlinModuleMetadata = function (abiVersion, moduleName, data) {
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package foo
|
||||
|
||||
// CHECK_NOT_CALLED: isTypeOfOrNull
|
||||
// CHECK_NULLS_COUNT: function=box count=8
|
||||
// CHECK_NULLS_COUNT: function=box count=10
|
||||
|
||||
inline
|
||||
fun <reified T> Any?.isTypeOfOrNull() = this is T?
|
||||
|
||||
Reference in New Issue
Block a user