Fixed bug in DefaultArgs lowering with vararg arguments + tests
This commit is contained in:
+2
-2
@@ -45,11 +45,11 @@ enum class KonanPhase(val description: String,
|
||||
/* ... ... */ LOWER_CALLABLES("Callable references Lowering", LOWER_DELEGATION),
|
||||
/* ... ... */ LOWER_LOCAL_FUNCTIONS("Local Function Lowering", LOWER_SHARED_VARIABLES, LOWER_CALLABLES),
|
||||
/* ... ... */ LOWER_INTEROP_PART2("Interop lowering, part 2", LOWER_LOCAL_FUNCTIONS),
|
||||
/* ... ... */ LOWER_VARARG("Vararg lowering", LOWER_CALLABLES),
|
||||
/* ... ... */ LOWER_COMPILE_TIME_EVAL("Compile time evaluation lowering", LOWER_VARARG),
|
||||
/* ... ... */ LOWER_TAILREC("tailrec lowering", LOWER_LOCAL_FUNCTIONS),
|
||||
/* ... ... */ LOWER_FINALLY("Finally blocks lowering", LOWER_INITIALIZERS, LOWER_LOCAL_FUNCTIONS, LOWER_TAILREC),
|
||||
/* ... ... */ LOWER_DEFAULT_PARAMETER_EXTENT("Default Parameter Extent Lowering", LOWER_TAILREC, LOWER_ENUMS),
|
||||
/* ... ... */ LOWER_VARARG("Vararg lowering", LOWER_CALLABLES, LOWER_DEFAULT_PARAMETER_EXTENT),
|
||||
/* ... ... */ LOWER_COMPILE_TIME_EVAL("Compile time evaluation lowering", LOWER_VARARG),
|
||||
/* ... ... */ LOWER_INNER_CLASSES("Inner classes lowering", LOWER_DEFAULT_PARAMETER_EXTENT),
|
||||
/* ... ... */ LOWER_BUILTIN_OPERATORS("BuiltIn Operators Lowering", LOWER_DEFAULT_PARAMETER_EXTENT),
|
||||
/* ... ... */ LOWER_COROUTINES("Coroutines lowering", LOWER_LOCAL_FUNCTIONS),
|
||||
|
||||
+3
-3
@@ -45,9 +45,9 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue
|
||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
@@ -311,8 +311,8 @@ class DefaultParameterInjector constructor(val context: CommonBackendContext): B
|
||||
maskValues[maskIndex] = maskValues[maskIndex] or (1 shl (i % 32))
|
||||
}
|
||||
val valueParameterDescriptor = realDescriptor.valueParameters[i]
|
||||
val pair = valueParameterDescriptor to (valueArgument ?: nullConst(expression, valueParameterDescriptor.type))
|
||||
return@mapIndexed pair
|
||||
val defaultValueArgument = if (valueParameterDescriptor.isVararg) null else nullConst(expression, valueParameterDescriptor.type)
|
||||
valueParameterDescriptor to (valueArgument ?: defaultValueArgument)
|
||||
})
|
||||
maskValues.forEachIndexed { i, maskValue ->
|
||||
params += maskParameterDescriptor(realFunction, i) to IrConstImpl.int(
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user