Add more tests on inline class boxing in covariant overrides

This commit is contained in:
Dmitry Petrov
2020-04-08 16:24:33 +03:00
parent 9615b20e5d
commit ddf7f53118
20 changed files with 443 additions and 12 deletions
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
inline class X(val x: Int)
fun useX(x: X): String = if (x.x == 42) "OK" else "fail: $x"
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
inline class X(val x: Int?)
fun useX(x: X): String = if (x.x == 42) "OK" else "fail: $x"
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
inline class X(val x: Int?)
fun useX(x: X): String = if (x.x == null) "OK" else "fail: $x"
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
inline class X(val x: String?)
fun useX(x: X): String = x.x ?: "fail: $x"
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
inline class X(val x: String?)
fun useX(x: X): String = if (x.x == null) "OK" else "fail: $x"
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
inline class X(val x: String)
fun useX(x: X): String = x.x
@@ -0,0 +1,34 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JVM_IR
inline class X(val x: Any)
interface IBar {
fun bar(): Any
}
interface IFoo : IBar {
fun foo(): Any
override fun bar(): X
}
class TestX : IFoo {
override fun foo(): X = X("O")
override fun bar(): X = X("K")
}
fun box(): String {
val t: IFoo = TestX()
val tFoo = t.foo()
if (tFoo !is X) {
throw AssertionError("X expected: $tFoo")
}
val t2: IBar = TestX()
val tBar = t.bar()
if (tBar !is X) {
throw AssertionError("X expected: $tBar")
}
return (t.foo() as X).x!!.toString() + (t2.bar() as X).x!!.toString()
}
@@ -0,0 +1,34 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JVM_IR
inline class X(val x: Any?)
interface IBar {
fun bar(): Any
}
interface IFoo : IBar {
fun foo(): Any
override fun bar(): X
}
class TestX : IFoo {
override fun foo(): X = X("O")
override fun bar(): X = X("K")
}
fun box(): String {
val t: IFoo = TestX()
val tFoo = t.foo()
if (tFoo !is X) {
throw AssertionError("X expected: $tFoo")
}
val t2: IBar = TestX()
val tBar = t.bar()
if (tBar !is X) {
throw AssertionError("X expected: $tBar")
}
return (t.foo() as X).x!!.toString() + (t2.bar() as X).x!!.toString()
}
@@ -0,0 +1,21 @@
inline class X(val x: Any)
interface IFoo<out T : X?> {
fun foo(): T
}
class Test : IFoo<X> {
override fun foo(): X = X("OK")
}
fun box(): String {
val t1: IFoo<X?> = Test()
val x1 = t1.foo()
if (x1 != X("OK")) throw AssertionError("x1: $x1")
val t2 = Test()
val x2 = t2.foo()
if (x2 != X("OK")) throw AssertionError("x2: $x2")
return "OK"
}
@@ -0,0 +1,23 @@
// IGNORE_BACKEND_FIR: JVM_IR
inline class X(val x: Any?)
interface IFoo<out T : X?> {
fun foo(): T
}
class Test : IFoo<X> {
override fun foo(): X = X("OK")
}
fun box(): String {
val t1: IFoo<X?> = Test()
val x1 = t1.foo()
if (x1 != X("OK")) throw AssertionError("x1: $x1")
val t2 = Test()
val x2 = t2.foo()
if (x2 != X("OK")) throw AssertionError("x2: $x2")
return "OK"
}
@@ -0,0 +1,24 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR
inline class X(val x: Any?)
interface IFoo<out T : X?> {
fun foo(): T
}
class Test : IFoo<X> {
override fun foo(): X = X(null)
}
fun box(): String {
val t1: IFoo<X?> = Test()
val x1 = t1.foo()
if (x1 != X(null)) throw AssertionError("x1: $x1")
val t2 = Test()
val x2 = t2.foo()
if (x2 != X(null)) throw AssertionError("x2: $x2")
return "OK"
}
@@ -0,0 +1,21 @@
inline class X(val x: Any)
interface IFoo {
fun foo(): X?
}
class Test : IFoo {
override fun foo(): X = X("OK")
}
fun box(): String {
val t1: IFoo = Test()
val x1 = t1.foo()
if (x1 != X("OK")) throw AssertionError("x1: $x1")
val t2 = Test()
val x2 = t2.foo()
if (x2 != X("OK")) throw AssertionError("x2: $x2")
return "OK"
}
@@ -0,0 +1,23 @@
// IGNORE_BACKEND_FIR: JVM_IR
inline class X(val x: Any?)
interface IFoo {
fun foo(): X?
}
class Test : IFoo {
override fun foo(): X = X("OK")
}
fun box(): String {
val t1: IFoo = Test()
val x1 = t1.foo()
if (x1 != X("OK")) throw AssertionError("x1: $x1")
val t2 = Test()
val x2 = t2.foo()
if (x2 != X("OK")) throw AssertionError("x2: $x2")
return "OK"
}
@@ -0,0 +1,23 @@
// IGNORE_BACKEND_FIR: JVM_IR
inline class X(val x: Any?)
interface IFoo {
fun foo(): X?
}
class Test : IFoo {
override fun foo(): X = X(null)
}
fun box(): String {
val t1: IFoo = Test()
val x1 = t1.foo()
if (x1 != X(null)) throw AssertionError("x1: $x1")
val t2 = Test()
val x2 = t2.foo()
if (x2 != X(null)) throw AssertionError("x2: $x2")
return "OK"
}