JVM BE: Add more tests for default arguments

- Inline class parameters should not be boxed.
- Empty vararg parameters should not allocate an empty array.
This commit is contained in:
Steven Schäfer
2019-08-05 13:54:39 +02:00
committed by Georgy Bronnikov
parent 9d7de8e9ec
commit 79f71f61d5
4 changed files with 52 additions and 0 deletions
@@ -0,0 +1,9 @@
// IGNORE_BACKEND: JVM_IR
// There is one ANEWARRAY instruction here, to generate the default parameter value.
fun default(vararg s: String = arrayOf("OK")) = s[0]
// This call on the other hand shouldn't allocate anything.
fun callDefault() = default()
// 1 ANEWARRAY
@@ -0,0 +1,23 @@
// LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
// FILE: classes.kt
inline class A(val i: Int)
inline class B(val a: A)
// FILE: test.kt
fun defaultA(a: A = A(1)) = a.i
fun defaultB(b: B = B(A(1))) = b.a.i
fun box(): String {
if (defaultA() != 1) return "Fail 1"
if (defaultB() != 1) return "Fail 2"
return "OK"
}
// @TestKt.class:
// 0 B.box-impl
// 0 A.box-impl
// 0 B.unbox-impl
// 0 A.unbox-impl