Allow IrConstTransformer to visit annotations of all declarations
This commit is contained in:
+9
-3
@@ -36,6 +36,8 @@ class IrConstTransformer(irModuleFragment: IrModuleFragment) : IrElementTransfor
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitField(declaration: IrField): IrStatement {
|
override fun visitField(declaration: IrField): IrStatement {
|
||||||
|
transformAnnotations(declaration)
|
||||||
|
|
||||||
val initializer = declaration.initializer
|
val initializer = declaration.initializer
|
||||||
val expression = initializer?.expression ?: return declaration
|
val expression = initializer?.expression ?: return declaration
|
||||||
if (expression is IrConst<*>) return declaration
|
if (expression is IrConst<*>) return declaration
|
||||||
@@ -47,8 +49,13 @@ class IrConstTransformer(irModuleFragment: IrModuleFragment) : IrElementTransfor
|
|||||||
return declaration
|
return declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClass(declaration: IrClass): IrStatement {
|
override fun visitDeclaration(declaration: IrDeclaration): IrStatement {
|
||||||
declaration.annotations.forEach {
|
transformAnnotations(declaration)
|
||||||
|
return super.visitDeclaration(declaration)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun transformAnnotations(annotationContainer: IrAnnotationContainer) {
|
||||||
|
annotationContainer.annotations.forEach {
|
||||||
for (i in 0 until it.valueArgumentsCount) {
|
for (i in 0 until it.valueArgumentsCount) {
|
||||||
val arg = it.getValueArgument(i) ?: continue
|
val arg = it.getValueArgument(i) ?: continue
|
||||||
if (arg.accept(IrCompileTimeChecker(mode = EvaluationMode.ONLY_BUILTINS), null)) {
|
if (arg.accept(IrCompileTimeChecker(mode = EvaluationMode.ONLY_BUILTINS), null)) {
|
||||||
@@ -57,7 +64,6 @@ class IrConstTransformer(irModuleFragment: IrModuleFragment) : IrElementTransfor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.visitClass(declaration)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrExpression.convertToConstIfPossible(type: IrType): IrExpression {
|
private fun IrExpression.convertToConstIfPossible(type: IrType): IrExpression {
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// IGNORE_BACKEND: JS_IR
|
// IGNORE_BACKEND: JS_IR
|
||||||
// IGNORE_BACKEND: JS_IR_ES6
|
// IGNORE_BACKEND: JS_IR_ES6
|
||||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
|||||||
Reference in New Issue
Block a user