[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:
committed by
Space Team
parent
f75b72990e
commit
8c748bfea4
+22
@@ -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
|
||||
+23
@@ -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"
|
||||
}
|
||||
+11
-4
@@ -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"
|
||||
}
|
||||
|
||||
+12
@@ -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
|
||||
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
// WITH_STDLIB
|
||||
// WITH_REFLECT
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses
|
||||
|
||||
import kotlin.reflect.KVisibility
|
||||
|
||||
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()
|
||||
|
||||
val constructors = Z::class.constructors
|
||||
require(constructors.map { it.visibility!! }.sorted() == listOf(KVisibility.PUBLIC, KVisibility.PUBLIC, KVisibility.INTERNAL, KVisibility.PRIVATE).sorted()) {
|
||||
constructors.map { it.visibility }.toString()
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// WITH_STDLIB
|
||||
// WITH_REFLECT
|
||||
// LANGUAGE: +ValueClasses
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses
|
||||
|
||||
import kotlin.reflect.KVisibility
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Z(val x: Int, val y: Int) {
|
||||
public constructor() : this(0)
|
||||
internal constructor(x: Long): this(x.toInt())
|
||||
private constructor(x: Int): this(x, -x)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val z1 = Z(111, 222)
|
||||
if (z1.x != 111) throw AssertionError()
|
||||
if (z1.y != 222) throw AssertionError()
|
||||
|
||||
val z2 = Z()
|
||||
if (z2.x != 0) throw AssertionError()
|
||||
if (z2.y != 0) throw AssertionError()
|
||||
|
||||
val z3 = Z(2222L)
|
||||
if (z3.x != 2222) throw AssertionError()
|
||||
if (z3.y != -2222) throw AssertionError()
|
||||
|
||||
val constructors = Z::class.constructors
|
||||
require(constructors.map { it.visibility!! }.sorted() == listOf(KVisibility.PUBLIC, KVisibility.PUBLIC, KVisibility.INTERNAL, KVisibility.PRIVATE).sorted()) {
|
||||
constructors.map { it.visibility }.toString()
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -161,12 +161,12 @@ public final class SimpleMfvc {
|
||||
public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: int, p2: java.lang.String, p3: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int, p2: java.lang.String, p3: int, p4: int, p5: java.lang.String): boolean
|
||||
public final static @org.jetbrains.annotations.NotNull method getA3-ge5QAg4(p0: int, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.String, p3: int, p4: int, @org.jetbrains.annotations.NotNull p5: java.lang.String): SimpleMfvc
|
||||
public final static method getA4-impl(p0: int, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.String): int
|
||||
public final static @org.jetbrains.annotations.NotNull method getA3-ge5QAg4(p0: int, p1: int, p2: java.lang.String, p3: int, p4: int, @org.jetbrains.annotations.NotNull p5: java.lang.String): SimpleMfvc
|
||||
public final static method getA4-impl(p0: int, p1: int, p2: java.lang.String): int
|
||||
public final static @org.jetbrains.annotations.NotNull method getB1-ge5QAg4(p0: int, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.String): SimpleMfvc
|
||||
public final static @org.jetbrains.annotations.NotNull method getB2-ge5QAg4(p0: int, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.String): SimpleMfvc
|
||||
public final static @org.jetbrains.annotations.NotNull method getB3-ge5QAg4(p0: int, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.String, p3: int, p4: int, @org.jetbrains.annotations.NotNull p5: java.lang.String): SimpleMfvc
|
||||
public final static @org.jetbrains.annotations.NotNull method getB4-impl(p0: int, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.String): SimpleMfvc
|
||||
public final static @org.jetbrains.annotations.NotNull method getB3-ge5QAg4(p0: int, p1: int, p2: java.lang.String, p3: int, p4: int, @org.jetbrains.annotations.NotNull p5: java.lang.String): SimpleMfvc
|
||||
public final static @org.jetbrains.annotations.NotNull method getB4-impl(p0: int, p1: int, p2: java.lang.String): SimpleMfvc
|
||||
private final static method getPrivate1-ge5QAg4(p0: int, p1: int, p2: java.lang.String, p3: int, p4: int, p5: java.lang.String): SimpleMfvc
|
||||
private final static method getPrivate2-ge5QAg4(p0: int, p1: int, p2: java.lang.String): SimpleMfvc
|
||||
private final static method getPrivate2-ge5QAg4(p0: int, p1: int, p2: java.lang.String, p3: int, p4: int, p5: java.lang.String): SimpleMfvc
|
||||
|
||||
+4
-4
@@ -191,11 +191,11 @@ public final class E {
|
||||
public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: int, p2: java.lang.String, p3: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int, p2: java.lang.String, p3: int, p4: int, p5: java.lang.String): boolean
|
||||
public final static @org.jetbrains.annotations.NotNull method getWithNonTrivialSetters-impl(p0: int, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.String): D
|
||||
public final static @org.jetbrains.annotations.NotNull method getWithNonTrivialSetters-impl(p0: int, p1: int, p2: java.lang.String): D
|
||||
public final @org.jetbrains.annotations.NotNull method getX(): D
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int, p1: int, p2: java.lang.String): int
|
||||
public final static method setWithNonTrivialSetters-j_b7x2A(p0: int, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.String, p3: int, p4: int, @org.jetbrains.annotations.NotNull p5: java.lang.String): void
|
||||
public final static method setWithNonTrivialSetters-j_b7x2A(p0: int, p1: int, p2: java.lang.String, p3: int, p4: int, @org.jetbrains.annotations.NotNull p5: java.lang.String): void
|
||||
public @org.jetbrains.annotations.NotNull method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int, p1: int, p2: java.lang.String): java.lang.String
|
||||
public synthetic final method unbox-impl-x(): D
|
||||
@@ -300,9 +300,9 @@ public final class R {
|
||||
public static method equals-impl(p0: int, p1: int, p2: int, p3: int, p4: java.lang.String, p5: java.util.List, p6: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int, p2: int, p3: int, p4: java.lang.String, p5: java.util.List, p6: int, p7: int, p8: int, p9: int, p10: java.lang.String, p11: java.util.List): boolean
|
||||
public @org.jetbrains.annotations.NotNull method getFakeOverrideMFVC(): R
|
||||
public static @org.jetbrains.annotations.NotNull method getFakeOverrideMFVC-impl(p0: int, p1: int, p2: int, p3: int, @org.jetbrains.annotations.NotNull p4: java.lang.String, @org.jetbrains.annotations.NotNull p5: java.util.List): R
|
||||
public static @org.jetbrains.annotations.NotNull method getFakeOverrideMFVC-impl(p0: int, p1: int, p2: int, p3: int, p4: java.lang.String, p5: java.util.List): R
|
||||
public method getFakeOverrideRegular(): int
|
||||
public static method getFakeOverrideRegular-impl(p0: int, p1: int, p2: int, p3: int, @org.jetbrains.annotations.NotNull p4: java.lang.String, @org.jetbrains.annotations.NotNull p5: java.util.List): int
|
||||
public static method getFakeOverrideRegular-impl(p0: int, p1: int, p2: int, p3: int, p4: java.lang.String, p5: java.util.List): int
|
||||
public final @org.jetbrains.annotations.NotNull method getT-GKOAj6k(): java.util.List
|
||||
public final method getX(): int
|
||||
public final method getY-pVg5ArA(): int
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
value class DPoint(/*inline */val x: Double/* = 1.0*/, /*inline */val y: Double/* = 2.0*/) {
|
||||
fun f1(a: Int, b: Int = -1, c: DPoint = DPoint(-2.0, -3.0)) = listOf(this, x, y, a, b, c)
|
||||
|
||||
constructor(x: Double, flip: Boolean = false): this(x, if (flip) -x else x)
|
||||
|
||||
companion object {
|
||||
inline operator fun invoke(): DPoint = DPoint(0.0, 0.0)
|
||||
}
|
||||
@@ -106,5 +108,9 @@ fun box(): String {
|
||||
require(RegularObject.pointToString() == "DPoint(x=0.0, y=0.0)") { RegularObject.pointToString() }
|
||||
require(getLineIntersectionPoint().toString() == "DPoint(x=0.0, y=0.0)") { getLineIntersectionPoint().toString() }
|
||||
|
||||
require(DPoint(1.0) == DPoint(1.0, 1.0)) { DPoint(1.0).toString() }
|
||||
require(DPoint(1.0, flip = false) == DPoint(1.0, 1.0)) { DPoint(1.0, flip = false).toString() }
|
||||
require(DPoint(1.0, flip = true) == DPoint(1.0, -1.0)) { DPoint(1.0, flip = true).toString() }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ public final class DPoint {
|
||||
static method <clinit>(): void
|
||||
private synthetic method <init>(p0: double, p1: double): void
|
||||
public synthetic final static method box-impl(p0: double, p1: double): DPoint
|
||||
public synthetic static method constructor-impl$default(p0: double, p1: boolean, p2: int, p3: kotlin.jvm.internal.DefaultConstructorMarker): DPoint
|
||||
public final static @org.jetbrains.annotations.NotNull method constructor-impl(p0: double, p1: boolean): DPoint
|
||||
public final static method constructor-impl(p0: double, p1: double): void
|
||||
public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: double, p1: double, p2: java.lang.Object): boolean
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public final class B {
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int, p1: int, p2: int, p3: int, p4: int, p5: int, p6: java.lang.String, p7: int, p8: int, p9: java.lang.String, p10: int, p11: int, p12: int, p13: int, p14: int, p15: int, p16: java.lang.String, p17: int, p18: int, p19: java.lang.String): int
|
||||
public @org.jetbrains.annotations.NotNull method toString(): java.lang.String
|
||||
public static @org.jetbrains.annotations.NotNull method toString-impl(p0: int, p1: int, p2: int, p3: int, p4: int, p5: int, @org.jetbrains.annotations.NotNull p6: java.lang.String, p7: int, p8: int, @org.jetbrains.annotations.NotNull p9: java.lang.String, p10: int, p11: int, p12: int, p13: int, p14: int, p15: int, @org.jetbrains.annotations.NotNull p16: java.lang.String, p17: int, p18: int, @org.jetbrains.annotations.NotNull p19: java.lang.String): java.lang.String
|
||||
public static @org.jetbrains.annotations.NotNull method toString-impl(p0: int, p1: int, p2: int, p3: int, p4: int, p5: int, p6: java.lang.String, p7: int, p8: int, p9: java.lang.String, p10: int, p11: int, p12: int, p13: int, p14: int, p15: int, p16: java.lang.String, p17: int, p18: int, p19: java.lang.String): java.lang.String
|
||||
public synthetic final method unbox-impl-a1(): A
|
||||
public synthetic final method unbox-impl-a1-f1(): int
|
||||
public synthetic final method unbox-impl-a1-f2(): int
|
||||
|
||||
@@ -13,7 +13,7 @@ public final class A {
|
||||
public final @org.jetbrains.annotations.NotNull method getValue1(): MyClass
|
||||
public final @org.jetbrains.annotations.NotNull method getValue2(): MyClass
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(@org.jetbrains.annotations.NotNull p0: MyClass, @org.jetbrains.annotations.NotNull p1: MyClass): int
|
||||
public static method hashCode-impl(p0: MyClass, p1: MyClass): int
|
||||
public @org.jetbrains.annotations.NotNull method toString(): java.lang.String
|
||||
public static method toString-impl(p0: MyClass, p1: MyClass): java.lang.String
|
||||
public synthetic final method unbox-impl-value1(): MyClass
|
||||
|
||||
@@ -18,9 +18,9 @@ public final class MFVC1 {
|
||||
public synthetic final static method box-impl(p0: java.lang.Number, p1: int): MFVC1
|
||||
public final static method constructor-impl(@org.jetbrains.annotations.NotNull p0: java.lang.Number, p1: int): void
|
||||
public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
|
||||
public final static method equals-impl(@org.jetbrains.annotations.NotNull p0: java.lang.Number, p1: int, p2: int, p3: int): boolean
|
||||
public final static method equals-impl(p0: java.lang.Number, p1: int, p2: int, p3: int): boolean
|
||||
public static method equals-impl(p0: java.lang.Number, p1: int, p2: java.lang.Object): boolean
|
||||
public final static method equals-impl0(@org.jetbrains.annotations.NotNull p0: java.lang.Number, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.Number, p3: int): boolean
|
||||
public final static method equals-impl0(p0: java.lang.Number, p1: int, @org.jetbrains.annotations.NotNull p2: java.lang.Number, p3: int): boolean
|
||||
public final method getOther(): int
|
||||
public final @org.jetbrains.annotations.NotNull method getX(): java.lang.Number
|
||||
public method hashCode(): int
|
||||
@@ -41,9 +41,9 @@ public final class MFVC2 {
|
||||
public synthetic final static method box-impl(p0: Generic, p1: int): MFVC2
|
||||
public final static method constructor-impl(@org.jetbrains.annotations.NotNull p0: Generic, p1: int): void
|
||||
public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
|
||||
public final static method equals-7Pc2DFw(@org.jetbrains.annotations.NotNull p0: Generic, p1: int, p2: double, p3: int, p4: int): boolean
|
||||
public final static method equals-7Pc2DFw(p0: Generic, p1: int, p2: double, p3: int, p4: int): boolean
|
||||
public static method equals-impl(p0: Generic, p1: int, p2: java.lang.Object): boolean
|
||||
public final static method equals-impl0(@org.jetbrains.annotations.NotNull p0: Generic, p1: int, @org.jetbrains.annotations.NotNull p2: Generic, p3: int): boolean
|
||||
public final static method equals-impl0(p0: Generic, p1: int, @org.jetbrains.annotations.NotNull p2: Generic, p3: int): boolean
|
||||
public final method getOther(): int
|
||||
public final @org.jetbrains.annotations.NotNull method getValue(): Generic
|
||||
public method hashCode(): int
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses
|
||||
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// Depends on KT-57973
|
||||
// JVM_TARGET: 1.8
|
||||
|
||||
interface Path {
|
||||
fun dispatch(maxDepth: Int = 42)
|
||||
fun Int.extension(maxDepth: Int = 42)
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class RealPath(val x: Int, val y: Int) : Path {
|
||||
override fun dispatch(maxDepth: Int) = Unit
|
||||
|
||||
fun childrenDispatch(recursively: Boolean): Unit =
|
||||
if (recursively) dispatch() else dispatch()
|
||||
|
||||
override fun Int.extension(maxDepth: Int) = Unit
|
||||
|
||||
fun Int.childrenExtension(recursively: Boolean): Unit =
|
||||
if (recursively) extension() else extension()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
RealPath(1, 2)
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// Depends on KT-57973
|
||||
// JVM_TARGET: 1.8
|
||||
|
||||
interface Path {
|
||||
fun dispatch(maxDepth: Int = 42)
|
||||
fun Int.extension(maxDepth: Int = 42)
|
||||
}
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class RealPath<T: Int>(val x: T, val y: T) : Path {
|
||||
override fun dispatch(maxDepth: Int) = Unit
|
||||
|
||||
fun childrenDispatch(recursively: Boolean): Unit =
|
||||
if (recursively) dispatch() else dispatch()
|
||||
|
||||
override fun Int.extension(maxDepth: Int) = Unit
|
||||
|
||||
fun Int.childrenExtension(recursively: Boolean): Unit =
|
||||
if (recursively) extension() else extension()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
RealPath(1, 2)
|
||||
return "OK"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// LANGUAGE: +MultiPlatformProjects, +ValueClasses
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_STDLIB
|
||||
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
// FILE: expect.kt
|
||||
|
||||
expect value class ExpectValue(val x: String, val y: String) {
|
||||
constructor(x: Int, y: Int)
|
||||
}
|
||||
|
||||
// MODULE: main()()(common)
|
||||
// TARGET_PLATFORM: JVM
|
||||
// FILE: actual.kt
|
||||
|
||||
@JvmInline
|
||||
actual value class ExpectValue actual constructor(actual val x: String, actual val y: String) {
|
||||
actual constructor(x: Int, y: Int) : this(if (x == 42) "O" else "Not OK: $x\n", if (y == -42) "K" else "Not OK: $y")
|
||||
}
|
||||
|
||||
fun box() = ExpectValue(42, -42).run { x + y }
|
||||
@@ -0,0 +1,28 @@
|
||||
// WITH_STDLIB
|
||||
// LANGUAGE: +ValueClasses
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Z(val x: Int, val y: Int) {
|
||||
public constructor() : this(0)
|
||||
internal constructor(x: Long): this(x.toInt())
|
||||
private constructor(x: Int): this(x, -x)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val z1 = Z(111, 222)
|
||||
if (z1.x != 111) throw AssertionError()
|
||||
if (z1.y != 222) throw AssertionError()
|
||||
|
||||
val z2 = Z()
|
||||
if (z2.x != 0) throw AssertionError()
|
||||
if (z2.y != 0) throw AssertionError()
|
||||
|
||||
val z3 = Z(2222L)
|
||||
if (z3.x != 2222) throw AssertionError()
|
||||
if (z3.y != -2222) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// LANGUAGE: +ValueClasses
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Z(val x: Int, val y: Int) {
|
||||
constructor(vararg ys: Long) : this(ys.size, -ys.size)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val z1 = Z(111, 222)
|
||||
if (z1.x != 111) throw AssertionError()
|
||||
if (z1.y != 222) throw AssertionError()
|
||||
|
||||
val z2 = Z()
|
||||
if (z2.x != 0) throw AssertionError()
|
||||
if (z2.y != 0) throw AssertionError()
|
||||
|
||||
val z3 = Z(2222L)
|
||||
if (z3.x != 1) throw AssertionError()
|
||||
if (z3.y != -1) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// WITH_STDLIB
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
|
||||
|
||||
OPTIONAL_JVM_INLINE_ANNOTATION
|
||||
value class Z<T: Int>(val x: T, val y: T) {
|
||||
constructor(vararg ys: Long) : this(ys.size as T, -ys.size as T)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
// val z1 = Z<Int>(111, 222) OVERLOAD_RESOLUTION_AMBIGUITY
|
||||
// if (z1.x != 111) throw AssertionError()
|
||||
// if (z1.y != 222) throw AssertionError()
|
||||
|
||||
val z2 = Z<Int>()
|
||||
if (z2.x != 0) throw AssertionError()
|
||||
if (z2.y != 0) throw AssertionError()
|
||||
|
||||
val z3 = Z<Int>(2222L)
|
||||
if (z3.x != 1) throw AssertionError()
|
||||
if (z3.y != -1) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
-4
@@ -8,14 +8,21 @@ val l = mutableListOf<Any>()
|
||||
|
||||
@JvmInline
|
||||
value class VC(val x: Int, val y: ULong) {
|
||||
constructor(xD: Double, yD: Double): this(xD.toInt() - 2, yD.toULong() - 2UL) {
|
||||
constructor(xD: Double, yD: Double) : this(xD.toInt() - 2, yD.toULong() - 2UL) {
|
||||
l.add(xD)
|
||||
l.add(yD)
|
||||
l.add(x)
|
||||
l.add(y)
|
||||
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(y)
|
||||
@@ -25,8 +32,8 @@ value class VC(val x: Int, val y: ULong) {
|
||||
|
||||
fun box(): String {
|
||||
val vc = VC(1, 2UL)
|
||||
require(vc == VC(3.0, 4.0)) { "$vc\n${VC(3.0, 4.0)}"}
|
||||
val actual = listOf(1, 2UL, vc, 1, 2UL, vc, 3.0, 4.0, 1, 2UL, vc)
|
||||
require(vc == VC(3.0, 4.0)) { "$vc\n${VC(3.0, 4.0)}" }
|
||||
val actual = listOf(1, 2UL, vc, 1, 2UL, vc, 3.0, 4.0, 1, 2UL, vc, 1.0, Long.MAX_VALUE)
|
||||
require(l == actual) { "$l\n$actual" }
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -7,12 +7,24 @@ 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(DD)LVC;
|
||||
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
|
||||
private final field y: long
|
||||
inner (local) class VC$Inner Inner
|
||||
private synthetic method <init>(p0: int, p1: long): void
|
||||
public synthetic final static method box-impl(p0: int, p1: long): VC
|
||||
public final static @org.jetbrains.annotations.NotNull method constructor-impl(p0: double, p1: double): VC
|
||||
|
||||
compiler/testData/codegen/bytecodeListing/valueClasses/nullabilityAnnotationsOnInlineClassMembers.kt
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// LANGUAGE: +ValueClasses
|
||||
// WITH_STDLIB
|
||||
|
||||
@JvmInline
|
||||
value class Test(val s: String, val s1: String) {
|
||||
fun memberFun(x: String) = s
|
||||
|
||||
fun String.memberExtFun() = s
|
||||
|
||||
val memberVal
|
||||
get() = s
|
||||
|
||||
val String.memberExtVal
|
||||
get() = s
|
||||
|
||||
|
||||
var memberVar
|
||||
get() = s
|
||||
set(value) {}
|
||||
|
||||
|
||||
var String.memberExtVar
|
||||
get() = s
|
||||
set(value) {}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
@kotlin.jvm.JvmInline
|
||||
@kotlin.Metadata
|
||||
public final class Test {
|
||||
// source: 'nullabilityAnnotationsOnInlineClassMembers.kt'
|
||||
private final @org.jetbrains.annotations.NotNull field s1: java.lang.String
|
||||
private final @org.jetbrains.annotations.NotNull field s: java.lang.String
|
||||
private synthetic method <init>(p0: java.lang.String, p1: java.lang.String): void
|
||||
public synthetic final static method box-impl(p0: java.lang.String, p1: java.lang.String): Test
|
||||
public final static method constructor-impl(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: java.lang.String): void
|
||||
public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: java.lang.String, p1: java.lang.String, p2: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: java.lang.String, p1: java.lang.String, p2: java.lang.String, p3: java.lang.String): boolean
|
||||
public final static @org.jetbrains.annotations.NotNull method getMemberExtVal-impl(p0: java.lang.String, p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: java.lang.String): java.lang.String
|
||||
public final static @org.jetbrains.annotations.NotNull method getMemberExtVar-impl(p0: java.lang.String, p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: java.lang.String): java.lang.String
|
||||
public final static @org.jetbrains.annotations.NotNull method getMemberVal-impl(p0: java.lang.String, p1: java.lang.String): java.lang.String
|
||||
public final static @org.jetbrains.annotations.NotNull method getMemberVar-impl(p0: java.lang.String, p1: java.lang.String): java.lang.String
|
||||
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
|
||||
public final @org.jetbrains.annotations.NotNull method getS1(): java.lang.String
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: java.lang.String, p1: java.lang.String): int
|
||||
public final static @org.jetbrains.annotations.NotNull method memberExtFun-impl(p0: java.lang.String, p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: java.lang.String): java.lang.String
|
||||
public final static @org.jetbrains.annotations.NotNull method memberFun-impl(p0: java.lang.String, p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: java.lang.String): java.lang.String
|
||||
public final static method setMemberExtVar-impl(p0: java.lang.String, p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: java.lang.String, @org.jetbrains.annotations.NotNull p3: java.lang.String): void
|
||||
public final static method setMemberVar-impl(p0: java.lang.String, p1: java.lang.String, @org.jetbrains.annotations.NotNull p2: java.lang.String): void
|
||||
public @org.jetbrains.annotations.NotNull method toString(): java.lang.String
|
||||
public static method toString-impl(p0: java.lang.String, p1: java.lang.String): java.lang.String
|
||||
public synthetic final method unbox-impl-s(): java.lang.String
|
||||
public synthetic final method unbox-impl-s1(): java.lang.String
|
||||
}
|
||||
Reference in New Issue
Block a user