Add accessor tests: inline class <-> companion

KT-26858 was fixed somewhere in the middle.

 #KT26858
This commit is contained in:
Dmitry Petrov
2018-09-24 14:24:24 +03:00
parent 850d72f13f
commit bffe9e45e8
11 changed files with 236 additions and 0 deletions
@@ -0,0 +1,12 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class R(private val r: Int) {
fun test() = ok()
companion object {
private fun ok() = "OK"
}
}
fun box() = R(0).test()
@@ -0,0 +1,12 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class R(private val r: Long) {
fun test() = ok()
companion object {
private fun ok() = "OK"
}
}
fun box() = R(0).test()
@@ -0,0 +1,12 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class R(private val r: Int) {
private fun ok() = "OK"
companion object {
fun test(r: R) = r.ok()
}
}
fun box() = R.test(R(0))
@@ -0,0 +1,12 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class R(private val r: Long) {
private fun ok() = "OK"
companion object {
fun test(r: R) = r.ok()
}
}
fun box() = R.test(R(0))
@@ -0,0 +1,14 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JS, JS_IR, JVM_IR
// WITH_RUNTIME
inline class R(private val r: Int) {
fun test() = ok()
companion object {
@JvmStatic
private fun ok() = "OK"
}
}
fun box() = R(0).test()
@@ -0,0 +1,24 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Direction(private val direction: Int) {
fun dx() = dx[direction]
fun dy() = dy[direction]
companion object {
private val dx = intArrayOf(0, 1, 0, -1)
private val dy = intArrayOf(-1, 0, 1, 0)
}
}
fun box(): String {
val dirs = arrayOf(Direction(0), Direction(1), Direction(2), Direction(3))
val expectedDx = intArrayOf(0, 1, 0, -1)
val expectedDy = intArrayOf(-1, 0, 1, 0)
for (i in 0 .. 3) {
if (dirs[i].dx() != expectedDx[i]) throw AssertionError()
if (dirs[i].dy() != expectedDy[i]) throw AssertionError()
}
return "OK"
}