Merge K2 box tests to main box tests

This commit is contained in:
Alexander Udalov
2023-03-23 12:28:07 +01:00
committed by Space Team
parent 14c2030595
commit d3be38476a
32 changed files with 584 additions and 402 deletions
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
class A {
val a: Number
private field = 1
val b: Number
internal field = a + 3
}
fun box(): String {
return if (A().b + 20 == 24) {
"OK"
} else {
"fail: A().b = " + A().b.toString()
}
}
@@ -0,0 +1,11 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// WITH_STDLIB
val items: List<String>
field = mutableListOf()
fun box(): String {
items.add("OK")
return items.last()
}
@@ -0,0 +1,11 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
class Base {
val x: CharSequence
internal field: String = "OK"
}
fun box(): String {
return Base().x
}
@@ -0,0 +1,13 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
class Base {
val x: CharSequence
internal field: String = "OK"
val s: String get() = x
}
fun box(): String {
return Base().s
}
@@ -0,0 +1,12 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
class Base {
val x: CharSequence
internal field: String = "OK"
}
val s: String get() = Base().x
fun box(): String {
return s
}
@@ -0,0 +1,12 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
class Base {
val x: CharSequence
internal field: String = "OK"
}
val s: String = Base().x
fun box(): String {
return s
}
@@ -0,0 +1,16 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
open class Base {
open val x: CharSequence = "BASE"
// field = "BASE"
}
class Ok : Base() {
override val x: CharSequence
internal field: String = "OK"
}
fun box(): String {
return Ok().x
}
@@ -0,0 +1,62 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
interface I {
val number: Number
}
fun test1(): String? {
val it = object : I {
final override val number: Number
field = 10
val next get() = number + 1
}
return if (it.next != 11) {
"[1] ${it.number}, ${it.next}"
} else {
null
}
}
fun test2(): String? {
class Local : I {
final override val number: Number
internal field = 42
}
return if (Local().number + 3 != 45) {
"[2] " + Local().number.toString()
} else {
null
}
}
fun test3(): String? {
val it = object : I {
override val number: Number
field = "100"
get() {
return field.length
}
}
return if (it.number != 3) {
"[3] " + it.number.toString()
} else {
null
}
}
fun box(): String {
val problem = test1()
?: test2()
?: test3()
return if (problem != null) {
"fail: " + problem
} else {
"OK"
}
}
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
interface Storage {
val s: String
}
class ImmutableStorage(override val s: String) : Storage
class MutableStorage(override var s: String) : Storage {
fun asImmutable() = ImmutableStorage(s)
}
class My {
val storage: Storage
field = MutableStorage("OK")
get() = field.asImmutable()
}
fun box(): String {
val my = My()
if (my.storage is MutableStorage) {
return "MUTABLE"
}
return my.storage.s
}
@@ -0,0 +1,43 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
fun createString() = "AAA" + "BBB"
class A {
var it: Int
field = 3.14
get() = (field + 10).toInt()
set(value) {
field = (value - 10).toDouble()
if (field < -3 || -1 < field) {
throw Exception("fail: value = $value, field = $field")
}
}
var that: Int
field = createString() + "!"
get() = field.length
set(value) {
field = value.toString()
if (field != "17") {
throw Exception("fail: value = $value, field = $field")
}
}
}
fun box(): String {
try {
val a = A()
val it: Int = A().it and 10
a.it = it
val that: Int = a.that
a.that = that + 10
} catch (e: Exception) {
return e.message ?: "fail"
}
return "OK"
}
@@ -0,0 +1,19 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
var that: Int
lateinit field: String
get() = field.length
set(value) {
field = value.toString()
}
fun box(): String {
that = 1
return if (that == 1) {
"OK"
} else {
"fail: $that"
}
}
@@ -0,0 +1,33 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
open class A {
open var it: Number
private field = 3
set(value) {
field = value.toInt()
}
fun test(): String {
// Note that `it` is open,
// so no smart type narrowing
// is possible, and we expect
// here a call to the possibly
// overridden getter
return if (it.toInt() + 1 == 11) {
"OK"
} else {
"fail: $it"
}
}
}
open class B : A() {
override var it: Number
get() = 10.12
set(value) {}
}
fun box(): String {
return B().test()
}