From f7f50ca8423a9429f543a4d688d1391cacca5d86 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 31 Jan 2023 11:41:14 +0100 Subject: [PATCH] [FIR2IR] Use cached IrEnumEntry when available in Fir2IrConverter Calling createIrEnumEntry lead to "IllegalStateException: Fir2IrEnumEntrySymbol for [declaration] is already bound" when the IrEnumEntry was already created previously, e.g. by an annotation call referencing it. ^KT-54079 Fixed --- .../kotlin/fir/backend/Fir2IrConverter.kt | 2 +- .../codegen/boxWithStdLib/enum/k54079.kt | 41 +++++++++++++++++++ ...rSpecificBlackBoxCodegenTestGenerated.java | 16 ++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/fir2ir/testData/codegen/boxWithStdLib/enum/k54079.kt diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt index ba8334f1f9c..2e0862879f8 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt @@ -403,7 +403,7 @@ class Fir2IrConverter( null } is FirEnumEntry -> { - classifierStorage.createIrEnumEntry(declaration, parent as IrClass) + classifierStorage.getIrEnumEntry(declaration, parent as IrClass) } is FirAnonymousInitializer -> { declarationStorage.createIrAnonymousInitializer(declaration, parent as IrClass) diff --git a/compiler/fir/fir2ir/testData/codegen/boxWithStdLib/enum/k54079.kt b/compiler/fir/fir2ir/testData/codegen/boxWithStdLib/enum/k54079.kt new file mode 100644 index 00000000000..7af71b75a3e --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/boxWithStdLib/enum/k54079.kt @@ -0,0 +1,41 @@ +open class Arguments { + @GradleOption( + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, + gradleInputType = GradleInputTypes.INPUT, + ) + val useK2: Boolean by lazy { false } +} + +class JvmArguments : Arguments() { + @GradleOption( + value = DefaultValue.BOOLEAN_FALSE_DEFAULT, + gradleInputType = GradleInputTypes.INPUT, + ) + val specific: Boolean by lazy { true } +} + +@Retention(AnnotationRetention.RUNTIME) +annotation class GradleOption( + val value: DefaultValue, + val gradleInputType: GradleInputTypes +) + +enum class GradleInputTypes( + val typeAsString: String +) { + INPUT("org.gradle.api.tasks.Input"), + INTERNAL("org.gradle.api.tasks.Internal"); + + override fun toString(): String { + return typeAsString + } +} + +enum class DefaultValue { + BOOLEAN_FALSE_DEFAULT, + BOOLEAN_TRUE_DEFAULT, +} + +fun box(): String { + return "OK" +} diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirSpecificBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirSpecificBlackBoxCodegenTestGenerated.java index 2f423f954b4..24f21ff2eec 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirSpecificBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirSpecificBlackBoxCodegenTestGenerated.java @@ -129,6 +129,22 @@ public class FirSpecificBlackBoxCodegenTestGenerated extends AbstractFirBlackBox KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/boxWithStdLib"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/codegen/boxWithStdLib/enum") + @TestDataPath("$PROJECT_ROOT") + public class Enum { + @Test + public void testAllFilesPresentInEnum() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/boxWithStdLib/enum"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("k54079.kt") + public void testK54079() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/boxWithStdLib/enum/k54079.kt"); + } + } + @Nested @TestMetadata("compiler/fir/fir2ir/testData/codegen/boxWithStdLib/properties") @TestDataPath("$PROJECT_ROOT")