Fix inline class coercion in default parameter values

#KT-27358
This commit is contained in:
Dmitry Petrov
2018-10-02 17:32:53 +03:00
parent c2315f065a
commit 8ce1d09f8a
10 changed files with 183 additions and 1 deletions
@@ -0,0 +1,15 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Z(val z: Int)
class Test(val z: Z = Z(42)) {
fun test() = z.z
}
fun box(): String {
if (Test().test() != 42) throw AssertionError()
if (Test(Z(123)).test() != 123) throw AssertionError()
return "OK"
}
@@ -0,0 +1,24 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Z(val z: Int)
interface ITest {
fun testDefault(z: Z = Z(42)) = z.z
fun testOverridden(z: Z = Z(42)): Int
}
class Test : ITest {
override fun testOverridden(z: Z) = z.z
}
fun box(): String {
if (Test().testDefault() != 42) throw AssertionError()
if (Test().testDefault(Z(123)) != 123) throw AssertionError()
if (Test().testOverridden() != 42) throw AssertionError()
if (Test().testOverridden(Z(123)) != 123) throw AssertionError()
return "OK"
}
@@ -0,0 +1,13 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Z(val z: Int)
fun test(z: Z = Z(42)) = z.z
fun box(): String {
if (test() != 42) throw AssertionError()
if (test(Z(123)) != 123) throw AssertionError()
return "OK"
}
@@ -0,0 +1,29 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
interface IFoo {
fun foo(): String
}
inline class Z(val z: Int) : IFoo {
override fun foo() = z.toString()
}
fun testNullable(z: Z? = Z(42)) = z!!.z
fun testAny(z: Any = Z(42)) = (z as Z).z
fun testInterface(z: IFoo = Z(42)) = z.foo()
fun box(): String {
if (testNullable() != 42) throw AssertionError()
if (testNullable(Z(123)) != 123) throw AssertionError()
if (testAny() != 42) throw AssertionError()
if (testAny(Z(123)) != 123) throw AssertionError()
if (testInterface() != "42") throw AssertionError()
if (testInterface(Z(123)) != "123") throw AssertionError()
return "OK"
}