[IR] Add more tests for inline/value classes secondary constructors

Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-55333
This commit is contained in:
Evgeniy.Zhelenskiy
2023-04-12 00:59:14 +02:00
committed by Space Team
parent f75b72990e
commit 8c748bfea4
52 changed files with 909 additions and 31 deletions
@@ -0,0 +1,22 @@
// LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
// MODULE: common
// TARGET_PLATFORM: Common
// FILE: expect.kt
expect value class ExpectValue(val x: String) {
constructor(x: Int)
}
// MODULE: main()()(common)
// TARGET_PLATFORM: JVM
// FILE: actual.kt
@JvmInline
actual value class ExpectValue actual constructor(actual val x: String) {
actual constructor(x: Int) : this(if (x == 42) "OK" else "Not OK: $x")
}
fun box() = ExpectValue(42).x
@@ -0,0 +1,23 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses
OPTIONAL_JVM_INLINE_ANNOTATION
value class Z(val x: Int) {
public constructor() : this(0)
internal constructor(x: Long, y: Int): this(x.toInt(), y.toInt())
private constructor(x: Int, y: Int): this(x + y)
}
fun box(): String {
val z1 = Z(111)
if (z1.x != 111) throw AssertionError()
val z2 = Z()
if (z2.x != 0) throw AssertionError()
val z3 = Z(2222L, 100)
if (z3.x != 2322) throw AssertionError()
return "OK"
}
@@ -9,12 +9,19 @@ val l = mutableListOf<Any>()
OPTIONAL_JVM_INLINE_ANNOTATION
value class VC(val x: Int) {
constructor(xD: Double): this(-xD.toInt()) {
constructor(xD: Double) : this(-xD.toInt()) {
l.add(xD)
l.add(x)
l.add(this)
l.add(xD.let { it - 1.0 }.let(fun(x: Double) = x - 1.0))
class Inner(val x: Int) {
constructor(x: Long): this(x.toInt()) {
l.add(x)
}
}
Inner(Long.MAX_VALUE)
}
init {
l.add(x)
l.add(this)
@@ -23,8 +30,8 @@ value class VC(val x: Int) {
fun box(): String {
val vc = VC(1)
require(vc == VC(-1.0)) { "$vc\n${VC(-1.0)}"}
val actual = listOf(1, vc, 1, vc, -1.0, 1, vc)
require(vc == VC(-1.0)) { "$vc\n${VC(-1.0)}" }
val actual = listOf(1, vc, 1, vc, -1.0, 1, vc, -3.0, Long.MAX_VALUE)
require(l == actual) { "$l\n$actual" }
return "OK"
}
@@ -7,11 +7,23 @@ public final class SecondaryConstructorsWithBodyKt {
public final static @org.jetbrains.annotations.NotNull method getL(): java.util.List
}
@kotlin.Metadata
public final class VC$Inner {
// source: 'secondaryConstructorsWithBody.kt'
enclosing method VC.constructor-impl(D)I
private final field x: int
inner (local) class VC$Inner Inner
public method <init>(p0: int): void
public method <init>(p0: long): void
public final method getX(): int
}
@kotlin.jvm.JvmInline
@kotlin.Metadata
public final class VC {
// source: 'secondaryConstructorsWithBody.kt'
private final field x: int
inner (local) class VC$Inner Inner
private synthetic method <init>(p0: int): void
public synthetic final static method box-impl(p0: int): VC
public static method constructor-impl(p0: double): int