Fixed bug in DefaultArgs lowering with vararg arguments + tests

This commit is contained in:
Igor Chevdar
2018-04-20 13:32:13 +03:00
parent 4d9a8d85d1
commit da3cc22ce8
5 changed files with 48 additions and 5 deletions
+10
View File
@@ -362,6 +362,16 @@ task function_defaults_from_fake_override(type: RunKonanTest) {
source = "codegen/function/defaultsFromFakeOverride.kt"
}
task function_defaults_with_vararg1(type: RunKonanTest) {
goldValue = "Hello , Correct!\nHello World, Correct!\n , Correct!\n"
source = "codegen/function/defaultsWithVarArg1.kt"
}
task function_defaults_with_vararg2(type: RunKonanTest) {
goldValue = "1\n2\n42\n"
source = "codegen/function/defaultsWithVarArg2.kt"
}
task sum_3const(type: RunKonanTest) {
source = "codegen/function/sum_3const.kt"
}
@@ -0,0 +1,21 @@
package codegen.function.defaultsWithVarArg1
import kotlin.test.*
fun foo(s: String = "", vararg args: Any) {
if (args == null) {
println("Failed!")
} else {
print("$s ")
args.forEach {
print("$it")
}
println(", Correct!")
}
}
@Test fun runTest() {
foo("Hello")
foo("Hello", "World")
foo()
}
@@ -0,0 +1,12 @@
package codegen.function.defaultsWithVarArg2
import kotlin.test.*
fun foo(vararg arr: Int = intArrayOf(1, 2)) {
arr.forEach { println(it) }
}
@Test fun runTest() {
foo()
foo(42)
}