[CJS BE] don't crash when intersection types passed for a reified parameter
#KT-37163 Fixed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
// KT-37163
|
||||
// Case that was found in kotlinx.coroutines
|
||||
|
||||
fun test1() {
|
||||
@@ -20,18 +20,6 @@ public inline fun <reified T, R> combine(
|
||||
fun <T> flowOf(value: T): Flow<T> = TODO()
|
||||
interface Flow<out T>
|
||||
|
||||
// Simplified case
|
||||
|
||||
class In<in T>
|
||||
|
||||
inline fun <reified K> select(x: K, y: K): K = x
|
||||
interface A
|
||||
interface B
|
||||
|
||||
fun test2(a: In<A>, b: In<B>) {
|
||||
select(a, b)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
// See KT-37163
|
||||
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
class In<in T>
|
||||
|
||||
interface A
|
||||
interface B
|
||||
class C() : A, B
|
||||
|
||||
// TODO check real effects to fix the behavior when we reach consensus
|
||||
// and to be sure that something is not dropped by optimizations.
|
||||
|
||||
var l = ""
|
||||
fun log(s: String) {
|
||||
l += s + ";"
|
||||
}
|
||||
|
||||
fun consume(a: Any?) {}
|
||||
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
inline fun <reified K> select(x: K, y: Any): K where K : A, K : B {
|
||||
log((x is K).toString())
|
||||
log((y is K).toString())
|
||||
consume(K::class)
|
||||
log("KClass was created")
|
||||
consume(typeOf<K>())
|
||||
log("KType was created")
|
||||
consume(Array<K>(1) { x })
|
||||
log("array was created")
|
||||
return x as K
|
||||
}
|
||||
|
||||
fun test(a: Any, b: Any) {
|
||||
if (a is A && a is B) {
|
||||
select(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(C(), object : A, B {})
|
||||
test(C(), object : A {})
|
||||
test(C(), object : B {})
|
||||
test(C(), object {})
|
||||
test(C(), Any())
|
||||
|
||||
// if (
|
||||
// l != "true;true;KClass was created;KType was created;array was created;" +
|
||||
// "true;false;KClass was created;KType was created;array was created;" +
|
||||
// "true;false;KClass was created;KType was created;array was created;" +
|
||||
// "true;false;KClass was created;KType was created;array was created;" +
|
||||
// "true;false;KClass was created;KType was created;array was created;"
|
||||
// ) {
|
||||
// return "fail: $l"
|
||||
// }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
// See KT-37163
|
||||
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
class In<in T>
|
||||
|
||||
interface A
|
||||
interface B
|
||||
class C() : A, B
|
||||
|
||||
// TODO check real effects to fix the behavior when we reach consensus
|
||||
// and to be sure that something is not dropped by optimizations.
|
||||
|
||||
var l = ""
|
||||
fun log(s: String) {
|
||||
l += s + ";"
|
||||
}
|
||||
|
||||
fun consume(a: Any?) {}
|
||||
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
inline fun <reified K> select(x: K, y: Any): K where K : A, K : B {
|
||||
log((x is K).toString())
|
||||
log((y is K).toString())
|
||||
consume(K::class)
|
||||
log("KClass was created")
|
||||
consume(typeOf<K>())
|
||||
log("KType was created")
|
||||
consume(Array<K>(1) { x })
|
||||
log("array was created")
|
||||
return x as K
|
||||
}
|
||||
|
||||
// MODULE: main(m1)
|
||||
// FILE: b.kt
|
||||
fun test(a: Any, b: Any) {
|
||||
if (a is A && a is B) {
|
||||
select(a, b)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(C(), object : A, B {})
|
||||
test(C(), object : A {})
|
||||
test(C(), object : B {})
|
||||
test(C(), object {})
|
||||
test(C(), Any())
|
||||
|
||||
// if (
|
||||
// l != "true;true;KClass was created;KType was created;array was created;" +
|
||||
// "true;false;KClass was created;KType was created;array was created;" +
|
||||
// "true;false;KClass was created;KType was created;array was created;" +
|
||||
// "true;false;KClass was created;KType was created;array was created;" +
|
||||
// "true;false;KClass was created;KType was created;array was created;"
|
||||
// ) {
|
||||
// return "fail: $l"
|
||||
// }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
// See KT-37163
|
||||
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
class In<in T>
|
||||
|
||||
interface A
|
||||
interface B
|
||||
|
||||
// TODO check real effects to fix the behavior when we reach consensus
|
||||
// and to be sure that something is not dropped by optimizations.
|
||||
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
inline fun <reified K> select(x: K, y: K) {
|
||||
x is K
|
||||
x as K
|
||||
K::class
|
||||
typeOf<K>()
|
||||
Array<K>(1) { x }
|
||||
}
|
||||
fun test() {
|
||||
select(In<A>(), In<B>())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test()
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user