[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:
+11
-6
@@ -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.EvaluationMode
|
||||||
import org.jetbrains.kotlin.ir.interpreter.checker.IrInterpreterChecker
|
import org.jetbrains.kotlin.ir.interpreter.checker.IrInterpreterChecker
|
||||||
import org.jetbrains.kotlin.ir.interpreter.isPrimitiveArray
|
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.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(
|
internal abstract class IrConstAnnotationTransformer(
|
||||||
interpreter: IrInterpreter,
|
interpreter: IrInterpreter,
|
||||||
@@ -67,12 +69,15 @@ internal abstract class IrConstAnnotationTransformer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun IrExpression.transformSingleArg(expectedType: IrType): IrExpression {
|
private fun IrExpression.transformSingleArg(expectedType: IrType): IrExpression {
|
||||||
if (this.canBeInterpreted()) {
|
return when {
|
||||||
return this.interpret(failAsError = true).convertToConstIfPossible(expectedType)
|
this is IrGetEnumValue || this is IrClassReference -> this
|
||||||
} else if (this is IrConstructorCall) {
|
this is IrConstructorCall && this.type.isAnnotation() -> {
|
||||||
transformAnnotation(this)
|
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 {
|
private fun IrExpression.convertToConstIfPossible(type: IrType): IrExpression {
|
||||||
|
|||||||
Reference in New Issue
Block a user