Call factory method for primary constructors of inner classes

We might want to add 'init' blocks later, so now, for the sake of
binary compatibility with 1.3-RC binaries, we have to generate these
'constructor' calls.

Note that in some tests inline class boxing is no longer redundant,
because resulting value is passed to 'constructor' as an argument.
This commit is contained in:
Dmitry Petrov
2018-08-30 16:04:20 +03:00
parent b1016936b2
commit a2900282fd
13 changed files with 119 additions and 26 deletions
@@ -0,0 +1,24 @@
// !LANGUAGE: +InlineClasses
inline class Result<T>(val a: Any?)
fun box(): String {
val a = Result<Int>(1) // valueOf
val b = Result<String>("sample")
val c = Result<Result<Int>>(a)
val d = Result<Result<Int>>(Result<Int>(1)) // valueOf
if (a.a !is Int) throw AssertionError()
if (b.a !is String) throw AssertionError()
if (c.a !is Result<*>) throw AssertionError()
val ca = c.a as Result<*>
if (ca.a !is Int) throw AssertionError()
if (d.a !is Result<*>) throw AssertionError()
val da = d.a as Result<*>
if (da.a !is Int) throw AssertionError()
return "OK"
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +InlineClasses
// WITH_RUNTIME
// IGNORE_BACKEND: JVM_IR
inline class Z(val x: Int) {
constructor(vararg ys: Long) : this(ys.size)
}
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)
if (z3.x != 1) throw AssertionError()
return "OK"
}
@@ -12,6 +12,7 @@ fun f() {
// @TestKt.class:
// 0 INVOKESTATIC UInt\$Erased.box
// 0 INVOKESTATIC UInt\.box
// 0 INVOKEVIRTUAL UInt.unbox
// 0 valueOf
// 0 intValue
@@ -16,6 +16,7 @@ fun test() {
// @TestKt.class:
// 0 INVOKESTATIC Result\$Erased.box
// 2 INVOKESTATIC Result\.box
// 0 INVOKEVIRTUAL Result.unbox
// 2 valueOf
@@ -0,0 +1,10 @@
// !LANGUAGE: +InlineClasses
// FILE: Z.kt
inline class Z(val x: Int)
// FILE: test.kt
fun testZ() = Z(42)
// @TestKt.class:
// 1 INVOKESTATIC Z\.constructor \(I\)I
@@ -27,6 +27,7 @@ fun test(asInt: Result<Int>, asString: Result<String>, asResult: Result<Result<I
// @TestKt.class:
// 0 INVOKESTATIC Result\$Erased.box
// 0 INVOKESTATIC Result\.box
// 3 INVOKEVIRTUAL Result.unbox
// 0 valueOf