Files
kotlin-fork/compiler/testData/ir/irText/expressions/callableReferences/withVarargViewedAsArray.fir.kt.txt
T
Dmitriy Novozhilov b454fcc1e0 [FIR] Save IR dumps to .ir.txt files instead of .txt in tests
This is needed to avoid clashes between different dumps from different
  handlers
2021-10-12 17:26:36 +03:00

58 lines
1.1 KiB
Plaintext
Vendored

fun sum(vararg args: Int): Int {
var result: Int = 0
{ // BLOCK
val <iterator>: IntIterator = args.iterator()
while (<iterator>.hasNext()) { // BLOCK
val arg: Int = <iterator>.next()
{ // BLOCK
result = result.plus(other = arg)
}
}
}
return result
}
fun nsum(vararg args: Number): Int {
return sum(args = [*IntArray(size = args.<get-size>(), init = local fun <anonymous>(it: Int): Int {
return args.get(index = it).toInt()
}
)])
}
fun zap(vararg b: String, k: Int = 42) {
}
fun usePlainArgs(fn: Function2<Int, Int, Int>) {
}
fun usePrimitiveArray(fn: Function1<IntArray, Int>) {
}
fun useArray(fn: Function1<Array<Int>, Int>) {
}
fun useStringArray(fn: Function1<Array<String>, Unit>) {
}
fun testPlainArgs() {
usePlainArgs(fn = local fun sum(p0: Int, p1: Int): Int {
return sum(args = [p0, p1])
}
)
}
fun testPrimitiveArrayAsVararg() {
usePrimitiveArray(fn = ::sum)
}
fun testArrayAsVararg() {
useArray(fn = ::nsum)
}
fun testArrayAndDefaults() {
useStringArray(fn = local fun zap(p0: Array<out String>) {
zap(b = [*p0])
}
)
}