[IR] Report backend error if annotation's arg can't be evaluated

Just a safety measure to ensure that we will not produce the wrong code.
This commit is contained in:
Ivan Kylchik
2023-11-15 15:43:13 +01:00
committed by Space Team
parent 5d60c52e30
commit 2c38685486
@@ -17,8 +17,10 @@ import org.jetbrains.kotlin.ir.interpreter.IrInterpreter
import org.jetbrains.kotlin.ir.interpreter.checker.EvaluationMode
import org.jetbrains.kotlin.ir.interpreter.checker.IrInterpreterChecker
import org.jetbrains.kotlin.ir.interpreter.isPrimitiveArray
import org.jetbrains.kotlin.ir.util.toIrConst
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.ir.util.isAnnotation
import org.jetbrains.kotlin.ir.util.toIrConst
internal abstract class IrConstAnnotationTransformer(
interpreter: IrInterpreter,
@@ -67,12 +69,15 @@ internal abstract class IrConstAnnotationTransformer(
}
private fun IrExpression.transformSingleArg(expectedType: IrType): IrExpression {
if (this.canBeInterpreted()) {
return this.interpret(failAsError = true).convertToConstIfPossible(expectedType)
} else if (this is IrConstructorCall) {
transformAnnotation(this)
return when {
this is IrGetEnumValue || this is IrClassReference -> this
this is IrConstructorCall && this.type.isAnnotation() -> {
transformAnnotation(this)
this
}
this.canBeInterpreted() -> this.interpret(failAsError = true).convertToConstIfPossible(expectedType)
else -> error("Cannot evaluate IR expression in annotation:\n ${this.dump()}")
}
return this
}
private fun IrExpression.convertToConstIfPossible(type: IrType): IrExpression {