Support default parameter values for inline class constructors and funs
#KT-26908 #KT-26554 Move default parameter value tests to separate directory
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR
|
||||
|
||||
inline class Z(val z: Int)
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
inline class Z(val x: Int) {
|
||||
fun test(y: Int = 42) = x + y
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Z(800).test() != 842) throw AssertionError()
|
||||
if (Z(400).test(32) != 432) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
inline class Z(val x: Int = 1234)
|
||||
inline class L(val x: Long = 1234L)
|
||||
inline class S(val x: String = "foobar")
|
||||
|
||||
fun box(): String {
|
||||
if (Z().x != 1234) throw AssertionError()
|
||||
if (L().x != 1234L) throw AssertionError()
|
||||
if (S().x != "foobar") throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
inline class Z(val x: Int) {
|
||||
constructor(x: Long = 42L) : this(x.toInt())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (Z().x != 42) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JS, JS_IR, JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
data class RGBA(val rgba: Int)
|
||||
|
||||
inline class RgbaArray(val array: IntArray) {
|
||||
val size: Int get() = array.size
|
||||
|
||||
fun fill(value: RGBA, start: Int = 0, end: Int = this.size): Unit = array.fill(value.rgba, start, end)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val rgbas = RgbaArray(IntArray(10))
|
||||
rgbas.fill(RGBA(123456))
|
||||
for (i in rgbas.array.indices) {
|
||||
if (rgbas.array[i] != 123456) throw AssertionError()
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user