diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/evaluate/IrConstTransformer.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/evaluate/IrConstTransformer.kt index a5cf2719276..db3bdab328d 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/evaluate/IrConstTransformer.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/evaluate/IrConstTransformer.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.ir.interpreter.checker.EvaluationMode import org.jetbrains.kotlin.ir.interpreter.checker.IrCompileTimeChecker import org.jetbrains.kotlin.ir.interpreter.toIrConst import org.jetbrains.kotlin.ir.types.* +import org.jetbrains.kotlin.ir.util.isPrimitiveArray import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid fun evaluateConstants(irModuleFragment: IrModuleFragment) { @@ -98,8 +99,11 @@ class IrConstTransformer(private val interpreter: IrInterpreter, private val irF } private fun IrExpression.convertToConstIfPossible(type: IrType): IrExpression { - if (this !is IrConst<*> || type is IrErrorType) return this - if (type.isArray()) return this.convertToConstIfPossible((type as IrSimpleType).arguments.single().typeOrNull!!) - return this.value.toIrConst(type, this.startOffset, this.endOffset) + return when { + this !is IrConst<*> || type is IrErrorType -> this + type.isArray() -> this.convertToConstIfPossible((type as IrSimpleType).arguments.single().typeOrNull!!) + type.isPrimitiveArray() -> this.convertToConstIfPossible(this.type) + else -> this.value.toIrConst(type, this.startOffset, this.endOffset) + } } } diff --git a/compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt b/compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt index 6c4597fbd64..577b4c9e206 100644 --- a/compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt +++ b/compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME // FILE: A.java diff --git a/compiler/testData/ir/irText/declarations/annotations/javaAnnotationWithSingleArrayArgument.fir.txt b/compiler/testData/ir/irText/declarations/annotations/javaAnnotationWithSingleArrayArgument.fir.txt index 076ccf0515f..607a037801b 100644 --- a/compiler/testData/ir/irText/declarations/annotations/javaAnnotationWithSingleArrayArgument.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/javaAnnotationWithSingleArrayArgument.fir.txt @@ -1,8 +1,11 @@ FILE fqName: fileName:/C.kt - CLASS ANNOTATION_CLASS name:Anno modality:FINAL visibility:public superTypes:[kotlin.Annotation] + CLASS ANNOTATION_CLASS name:Anno modality:OPEN visibility:public superTypes:[kotlin.Annotation] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Anno CONSTRUCTOR visibility:public <> (token:kotlin.String) returnType:.Anno [primary] VALUE_PARAMETER name:token index:0 type:kotlin.String + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Anno modality:OPEN visibility:public superTypes:[kotlin.Annotation]' PROPERTY name:token visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:token type:kotlin.String visibility:private [final] EXPRESSION_BODY @@ -80,10 +83,13 @@ FILE fqName: fileName:/C.kt overridden: public final fun (): kotlin.Int declared in kotlin.Enum $this: VALUE_PARAMETER name: type:kotlin.Enum - CLASS ANNOTATION_CLASS name:Annos modality:FINAL visibility:public superTypes:[kotlin.Annotation] + CLASS ANNOTATION_CLASS name:Annos modality:OPEN visibility:public superTypes:[kotlin.Annotation] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Annos CONSTRUCTOR visibility:public <> (value:kotlin.Array<.Anno>) returnType:.Annos [primary] VALUE_PARAMETER name:value index:0 type:kotlin.Array<.Anno> + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Annos modality:OPEN visibility:public superTypes:[kotlin.Annotation]' PROPERTY name:value visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.Array<.Anno> visibility:private [final] EXPRESSION_BODY @@ -108,10 +114,13 @@ FILE fqName: fileName:/C.kt overridden: public open fun toString (): kotlin.String [fake_override] declared in kotlin.Annotation $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS ANNOTATION_CLASS name:Strings modality:FINAL visibility:public superTypes:[kotlin.Annotation] + CLASS ANNOTATION_CLASS name:Strings modality:OPEN visibility:public superTypes:[kotlin.Annotation] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Strings CONSTRUCTOR visibility:public <> (value:kotlin.Array) returnType:.Strings [primary] VALUE_PARAMETER name:value index:0 type:kotlin.Array + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Strings modality:OPEN visibility:public superTypes:[kotlin.Annotation]' PROPERTY name:value visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.Array visibility:private [final] EXPRESSION_BODY @@ -136,10 +145,13 @@ FILE fqName: fileName:/C.kt overridden: public open fun toString (): kotlin.String [fake_override] declared in kotlin.Annotation $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS ANNOTATION_CLASS name:Ints modality:FINAL visibility:public superTypes:[kotlin.Annotation] + CLASS ANNOTATION_CLASS name:Ints modality:OPEN visibility:public superTypes:[kotlin.Annotation] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Ints CONSTRUCTOR visibility:public <> (value:kotlin.IntArray) returnType:.Ints [primary] VALUE_PARAMETER name:value index:0 type:kotlin.IntArray + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Ints modality:OPEN visibility:public superTypes:[kotlin.Annotation]' PROPERTY name:value visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.IntArray visibility:private [final] EXPRESSION_BODY @@ -164,10 +176,13 @@ FILE fqName: fileName:/C.kt overridden: public open fun toString (): kotlin.String [fake_override] declared in kotlin.Annotation $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS ANNOTATION_CLASS name:Enums modality:FINAL visibility:public superTypes:[kotlin.Annotation] + CLASS ANNOTATION_CLASS name:Enums modality:OPEN visibility:public superTypes:[kotlin.Annotation] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Enums CONSTRUCTOR visibility:public <> (value:kotlin.Array<.E>) returnType:.Enums [primary] VALUE_PARAMETER name:value index:0 type:kotlin.Array<.E> + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Enums modality:OPEN visibility:public superTypes:[kotlin.Annotation]' PROPERTY name:value visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.Array<.E> visibility:private [final] EXPRESSION_BODY @@ -192,10 +207,13 @@ FILE fqName: fileName:/C.kt overridden: public open fun toString (): kotlin.String [fake_override] declared in kotlin.Annotation $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS ANNOTATION_CLASS name:Classes modality:FINAL visibility:public superTypes:[kotlin.Annotation] + CLASS ANNOTATION_CLASS name:Classes modality:OPEN visibility:public superTypes:[kotlin.Annotation] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Classes CONSTRUCTOR visibility:public <> (value:kotlin.Array>) returnType:.Classes [primary] VALUE_PARAMETER name:value index:0 type:kotlin.Array> + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Classes modality:OPEN visibility:public superTypes:[kotlin.Annotation]' PROPERTY name:value visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.Array> visibility:private [final] EXPRESSION_BODY @@ -228,11 +246,11 @@ FILE fqName: fileName:/C.kt INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[.A]' FUN FAKE_OVERRIDE name:test visibility:public modality:OPEN <> ($this:.A) returnType:kotlin.Unit [fake_override] annotations: - Annos(value = ) - Strings(value = ) - Ints(value = ) - Enums(value = ) - Classes(value = ) + Annos(value = Anno(token = 'OK')) + Strings(value = 'OK') + Ints(value = '42') + Enums(value = GET_ENUM 'ENUM_ENTRY name:EA' type=IrErrorType(null)) + Classes(value = CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Double modality:FINAL visibility:public superTypes:[kotlin.Number; kotlin.Comparable; java.io.Serializable]' type=IrErrorType(null)) overridden: public open fun test (): kotlin.Unit declared in .A $this: VALUE_PARAMETER name: type:.A diff --git a/compiler/testData/ir/irText/declarations/annotations/javaAnnotationWithSingleArrayArgument.kt b/compiler/testData/ir/irText/declarations/annotations/javaAnnotationWithSingleArrayArgument.kt index 30308c659e5..fd4b0fe5fc6 100644 --- a/compiler/testData/ir/irText/declarations/annotations/javaAnnotationWithSingleArrayArgument.kt +++ b/compiler/testData/ir/irText/declarations/annotations/javaAnnotationWithSingleArrayArgument.kt @@ -1,6 +1,5 @@ // SKIP_KT_DUMP // TARGET_BACKEND: JVM -// IGNORE_BACKEND_FIR: JVM_IR // FILE: A.java public class A {