[IR] Add new tests on inline to check issues with type parameters
#KT-58241
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// FILE: 1.kt
|
||||
interface I<TTTT> {
|
||||
fun get(): TTTT
|
||||
fun set(x: TTTT)
|
||||
|
||||
}
|
||||
interface J
|
||||
class X(val result: String) : J
|
||||
class Box<T>(val x : T) {
|
||||
inline fun getI(crossinline block : () -> Unit) : I<T> {
|
||||
val temp = x
|
||||
return object : I<T> {
|
||||
var t = temp
|
||||
override fun get() = t
|
||||
override fun set(y: T) {
|
||||
block()
|
||||
t = y
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Box<*>.getIExt() = getI() {}
|
||||
|
||||
// FILE: 2.kt
|
||||
fun box(): String {
|
||||
val xObject = Box(X("OK")).getIExt().get() as X
|
||||
return xObject.result
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
class Box<T>(val value: T) {
|
||||
inline fun run(block: (T) -> Unit) {
|
||||
block(value)
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
fun box(): String {
|
||||
Box("OK").run { outer ->
|
||||
return outer
|
||||
}
|
||||
|
||||
return "Fail"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// FILE: 1.kt
|
||||
class Box<T>(
|
||||
private var t: T
|
||||
) {
|
||||
fun set(t: T): T {
|
||||
this.t = t
|
||||
return t
|
||||
}
|
||||
fun get(): T = t
|
||||
}
|
||||
|
||||
inline fun <U> Box<U>.act(): U {
|
||||
val u = get()
|
||||
return set(u)
|
||||
}
|
||||
|
||||
fun foo(uuu: Box<*>): Any? {
|
||||
val x = uuu.act()
|
||||
return x
|
||||
}
|
||||
|
||||
// This code is not compilable
|
||||
// fun fooInlined(uuu: Box<*>) {
|
||||
// val u = get()
|
||||
// return set(u)
|
||||
// }
|
||||
|
||||
// FILE: 2.kt
|
||||
fun box(): String {
|
||||
return foo(Box("OK")).toString()
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// FILE: 1.kt
|
||||
interface I {
|
||||
fun f(): String
|
||||
}
|
||||
|
||||
interface J {
|
||||
fun f2(): String
|
||||
}
|
||||
|
||||
class X : I, J {
|
||||
override fun f(): String = "O"
|
||||
override fun f2(): String = "K"
|
||||
}
|
||||
|
||||
class Box<T>(val x: T) where T: Any, T : I, T: J {
|
||||
inline fun f(): String {
|
||||
val a = x
|
||||
return a.f() + a.f2()
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
fun box(): String {
|
||||
return Box(X()).f()
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// FILE: 1.kt
|
||||
open class Box<T>(
|
||||
private var t: T
|
||||
) {
|
||||
fun set(t: T): T {
|
||||
this.t = t
|
||||
return t
|
||||
}
|
||||
fun get(): T = t
|
||||
inline fun act(): T {
|
||||
val u = get()
|
||||
return set(u)
|
||||
}
|
||||
}
|
||||
class StringBox(t: String) : Box<String>(t)
|
||||
|
||||
fun foo(uuu: StringBox): String {
|
||||
val x = uuu.act()
|
||||
return x
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
fun box(): String {
|
||||
return foo(StringBox("OK"))
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// IGNORE_INLINER: IR
|
||||
// IGNORE_BACKEND: WASM
|
||||
|
||||
// FILE: 1.kt
|
||||
inline fun <U> unchecked(any: Any): Any {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val u: U = any as U
|
||||
return u as Any
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
fun box(): String {
|
||||
// in current inline implementation everyting works fine
|
||||
// but if we will reify all type parameters, then this example will fail on runtime
|
||||
return unchecked<Nothing>("OK").toString()
|
||||
}
|
||||
Reference in New Issue
Block a user