Is it safe to cast `IrVarargElement` into `IrExpre...
# compiler
t
Is it safe to cast
IrVarargElement
into
IrExpression
? The IDE shows an error if I try to use a non-expression as vararg argument, but the type structure allows
IrVarargElement
to be anything basically.
p
Well, there are currently only two childs of
IrVarargElement
. It's either any
IrExpression
or
IrSpreadElement
. The later corresponds to
Copy code
val a = intArrayOf(1, 2, 3) // IrVararg(IrExp(1), IrExp(2), IrExp(3)
val b = intArrayOf(4, 5, 6) // IrVararg(IrExp(4), IrExp(5), IrExp(6)
listOf(*a, *b) // IrVararg(IrSpread(IrGet(a)), IrSpread(IrGet(b)))
IrSpreadElement is not an expression, so it's not safe to cast in general case, unless you know something about the code you are processing. In the current language, there is nothing else can be in IR here. Technically, some compiler plugin can insert it's own implementor of interface, but it probably wouldn't work anyway, so I doubt someone really do this.
t
Thank you, this is very useful. I'll handle
IrSpreadElement
as well.