diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index dbfd42e696e..2ebc34439a1 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -19239,6 +19239,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/fir/selectingLambdas.kt"); } + @Test + @TestMetadata("StackOverflowInAnnotationLoader.kt") + public void testStackOverflowInAnnotationLoader() throws Exception { + runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java index 5775a32f9b6..7dfadd62224 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java @@ -19239,6 +19239,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated runTest("compiler/testData/codegen/box/fir/selectingLambdas.kt"); } + @Test + @TestMetadata("StackOverflowInAnnotationLoader.kt") + public void testStackOverflowInAnnotationLoader() throws Exception { + runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index 6a51247950c..0523fa4c5a2 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -19239,6 +19239,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/fir/selectingLambdas.kt"); } + @Test + @TestMetadata("StackOverflowInAnnotationLoader.kt") + public void testStackOverflowInAnnotationLoader() throws Exception { + runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/AnnotationsLoader.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/AnnotationsLoader.kt index 95a09513dfa..b6eee699ce9 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/AnnotationsLoader.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/AnnotationsLoader.kt @@ -98,10 +98,11 @@ internal class AnnotationsLoader(private val session: FirSession, private val ko override fun visitEnd() { visitExpression(name, buildArrayLiteral { - guessArrayTypeIfNeeded(name, elements)?.let { - coneTypeOrNull = it.coneTypeOrNull - } ?: elements.firstOrNull()?.resolvedType?.createOutArrayType()?.let { + @OptIn(UnresolvedExpressionTypeAccess::class) + elements.firstOrNull()?.coneTypeOrNull?.createOutArrayType()?.let { coneTypeOrNull = it + } ?: guessArrayTypeIfNeeded(name, elements)?.let { + coneTypeOrNull = it.coneTypeOrNull } argumentList = buildArgumentList { arguments += elements diff --git a/compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt b/compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt new file mode 100644 index 00000000000..707cebc0861 --- /dev/null +++ b/compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt @@ -0,0 +1,58 @@ +// TARGET_BACKEND: JVM_IR +// ISSUE: KT-62598 + +// MODULE: m1 +// FILE: m1.kt +interface Holder { + interface Entry { + @Annotation(value = [""]) + fun f() + } + + annotation class Annotation( + val value: Array, + ) +} + +interface ByteHolder { + interface Entry { + @Annotation(value = [1]) + fun f() + } + + annotation class Annotation( + val value: ByteArray, + ) +} + +interface HolderWithDefault { + interface Entry { + @Annotation + fun f() + } + + annotation class Annotation( + val value: Array = [""], + ) +} + +interface HolderWithEmpty { + interface Entry { + @Annotation(value = []) + fun f() + } + + annotation class Annotation( + val value: Array, + ) +} + +// MODULE: m2(m1) +// FILE: m2.kt +import Holder +import ByteHolder +import HolderWithDefault +// This line still provokes SOE in K2 +//import HolderWithEmpty + +fun box() = "OK" diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 66c5d677b50..259880650f6 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -19239,6 +19239,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/selectingLambdas.kt"); } + @Test + @TestMetadata("StackOverflowInAnnotationLoader.kt") + public void testStackOverflowInAnnotationLoader() throws Exception { + runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index fd9492f134f..b84279f147c 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -19239,6 +19239,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/fir/selectingLambdas.kt"); } + @Test + @TestMetadata("StackOverflowInAnnotationLoader.kt") + public void testStackOverflowInAnnotationLoader() throws Exception { + runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6096349cf8c..9022fff780c 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16030,6 +16030,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/fir/SamWithReceiverMavenProjectImportHandler.kt"); } + @TestMetadata("StackOverflowInAnnotationLoader.kt") + public void testStackOverflowInAnnotationLoader() throws Exception { + runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); + } + @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { runTest("compiler/testData/codegen/box/fir/staticImportFromEnum.kt");