Files
kotlin-fork/compiler/testData/codegen/box/callableReference/varargAndDefaults/innerConstructorWithVararg.kt
T
Mikhail Zarechenskiy 04e57f712e [NI] Introduce feature for passing function references with defaults
Relates to KT-8834, we continue reducing differences between old and new
 inference. Note that as for `SamConversionPerArgument`, this feature
 is enabled in the compiler and not in the IDE to avoid breaking code
 for those users that already enabled new inference in the compiler
2019-08-07 15:58:36 +03:00

35 lines
873 B
Kotlin
Vendored

// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
class Outer(val o: String) {
inner class Inner1(val i: Int, vararg v: String) {
val result = "I1" + o + i + if (v.size == 0) "E" else v[0]
}
inner class Inner2(val i: Int, vararg v: String = arrayOf("A")) {
val result = "I2" + o + i + v[0]
}
}
fun <T> use0(f: (Int) -> T) = f(11)
fun <T> use1(f: (Int, String) -> T) = f(12, "B")
fun box(): String {
val oouter = Outer("O")
val r1 = use0(oouter::Inner1).result
if (r1 != "I1O11E") return "Fail1: $r1"
val r2 = use1(oouter::Inner1).result
if (r2 != "I1O12B") return "Fail2: $r2"
val r3 = use0(oouter::Inner2).result
if (r3 != "I2O11A") return "Fail3: $r3"
val r4 = use1(oouter::Inner2).result
if (r4 != "I2O12B") return "Fail4: $r4"
return "OK"
}