IrConstTransformer: handle vararg with spread elements properly
This commit is contained in:
committed by
Mikhail Glukhikh
parent
5600eefea5
commit
db9d42c153
+16
-5
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.IrStatement
|
|||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
|
|
||||||
@@ -60,18 +61,28 @@ class IrConstTransformer(irBuiltIns: IrBuiltIns) : IrElementTransformerVoid() {
|
|||||||
for (i in 0 until annotation.valueArgumentsCount) {
|
for (i in 0 until annotation.valueArgumentsCount) {
|
||||||
val arg = annotation.getValueArgument(i) ?: continue
|
val arg = annotation.getValueArgument(i) ?: continue
|
||||||
when (arg) {
|
when (arg) {
|
||||||
is IrVararg -> arg.transformVarArg()
|
is IrVararg -> annotation.putValueArgument(i, arg.transformVarArg())
|
||||||
else -> annotation.putValueArgument(i, arg.transformSingleArg(annotation.symbol.owner.valueParameters[i].type))
|
else -> annotation.putValueArgument(i, arg.transformSingleArg(annotation.symbol.owner.valueParameters[i].type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrVararg.transformVarArg() {
|
private fun IrVararg.transformVarArg(): IrVararg {
|
||||||
for (i in this.elements.indices) {
|
if (elements.isEmpty()) return this
|
||||||
val irVarargElement = this.elements[i] as? IrExpression ?: continue
|
val newIrVararg = IrVarargImpl(this.startOffset, this.endOffset, this.type, this.varargElementType)
|
||||||
this.putElement(i, irVarargElement.transformSingleArg(this.varargElementType))
|
for (element in this.elements) {
|
||||||
|
when (element) {
|
||||||
|
is IrExpression -> newIrVararg.addElement(element.transformSingleArg(this.varargElementType))
|
||||||
|
is IrSpreadElement -> {
|
||||||
|
when (val expression = element.expression) {
|
||||||
|
is IrVararg -> expression.transformVarArg().elements.forEach { newIrVararg.addElement(it) }
|
||||||
|
else -> newIrVararg.addElement(expression.transformSingleArg(this.varargElementType))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return newIrVararg
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrExpression.transformSingleArg(expectedType: IrType): IrExpression {
|
private fun IrExpression.transformSingleArg(expectedType: IrType): IrExpression {
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// WITH_REFLECT
|
// WITH_REFLECT
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
import java.util.Arrays
|
import java.util.Arrays
|
||||||
|
|||||||
Vendored
+1
-1
@@ -29,5 +29,5 @@ FILE fqName:<root> fileName:/spreadOperatorInAnnotationArguments.kt
|
|||||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||||
FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||||
annotations:
|
annotations:
|
||||||
A(xs = [SPREAD_ELEMENT, SPREAD_ELEMENT])
|
A(xs = ['a', 'b'])
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
Reference in New Issue
Block a user