Files
kotlin-fork/compiler/testData/codegen/box/callableReference/varargAndDefaults/boundReferences.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

48 lines
1.1 KiB
Kotlin
Vendored

// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
// WITH_RUNTIME
import kotlin.test.assertEquals
class C(val expected: Int) {
fun memberVararg(i: Int, vararg s: String) {
assertEquals(expected, i)
assertEquals(0, s.size)
}
fun memberDefault(i: Int, s: String = "") {
assertEquals(expected, i)
assertEquals("", s)
}
fun memberBoth(i: Int, s: String = "", vararg t: String) {
assertEquals(expected, i)
assertEquals("", s)
assertEquals(0, t.size)
}
}
fun C.extensionVararg(i: Int, vararg s: String) {
memberVararg(i, *s)
}
fun C.extensionDefault(i: Int, s: String = "") {
memberDefault(i, s)
}
fun C.extensionBoth(i: Int, s: String = "", vararg t: String) {
memberBoth(i, s, *t)
}
fun test(f: (Int) -> Unit, p: Int) = f(p)
fun box(): String {
test(C(42)::memberVararg, 42)
test(C(42)::memberDefault, 42)
test(C(42)::memberBoth, 42)
test(C(42)::extensionVararg, 42)
test(C(42)::extensionDefault, 42)
test(C(42)::extensionBoth, 42)
return "OK"
}