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:
Dmitry Petrov
2018-10-02 18:04:45 +03:00
parent 8ce1d09f8a
commit f68ce4b35b
26 changed files with 435 additions and 135 deletions
@@ -1,5 +1,5 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND: JVM_IR, JS_IR
inline class Z(val z: Int)
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -0,0 +1,5 @@
// !LANGUAGE: +InlineClasses
inline class Test(val x: Int = 0) {
constructor(a: Int, b: Int, c: Int = 42) : this(a + b + c)
}
@@ -0,0 +1,19 @@
@kotlin.Metadata
public final class Test {
private final field x: int
private synthetic method <init>(p0: int): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(p0: int): Test
public synthetic static method constructor-impl$default(p0: int, p1: int, p2: int, p3: int, p4: kotlin.jvm.internal.DefaultConstructorMarker): int
public synthetic static method constructor-impl$default(p0: int, p1: int, p2: kotlin.jvm.internal.DefaultConstructorMarker): int
public static method constructor-impl(p0: int): int
public static method constructor-impl(p0: int, p1: int, p2: int): int
public method equals(p0: java.lang.Object): boolean
public static method equals-impl(p0: int, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean
public final static method equals-impl0(p0: int, p1: int): boolean
public final method getX(): int
public method hashCode(): int
public static method hashCode-impl(p0: int): int
public method toString(): java.lang.String
public static @org.jetbrains.annotations.NotNull method toString-impl(p0: int): java.lang.String
public synthetic final method unbox-impl(): int
}