From 7422571c72922cf47db731c6d9604f698f10e9d4 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 27 Jul 2021 15:18:34 +0300 Subject: [PATCH] [FIR] Fix cycle when loading nested enum within java annotation --- .../j+k/AnnotationWithEnum.fir.txt | 3 +++ .../resolveWithStdlib/j+k/AnnotationWithEnum.kt | 17 +++++++++++++++++ .../runners/FirDiagnosticTestGenerated.java | 6 ++++++ ...irDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../kotlin/fir/java/JavaSymbolProvider.kt | 5 ++++- ...agnosisCompilerFirTestdataTestGenerated.java | 6 ++++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.kt diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.fir.txt new file mode 100644 index 00000000000..e03e6833019 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.fir.txt @@ -0,0 +1,3 @@ +FILE: jvm.kt + @R|some/Nls|(R|some/Nls.Capitalization.Title|) public final fun f(): R|kotlin/Unit| { + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.kt new file mode 100644 index 00000000000..9f6e402a052 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.kt @@ -0,0 +1,17 @@ +// FILE: some/Nls.java +package some +public @interface Nls { + Capitalization capitalization() default Capitalization.NotSpecified; + + enum Capitalization { NotSpecified, Title, Sentence } +} + + +// FILE: jvm.kt +import some.Nls.Capitalization.* +import some.Nls + +@Nls(Title) +fun f() { + +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index f743752de7d..51210f244c1 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -5003,6 +5003,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k"), Pattern.compile("^([^.]+)\\.kt$"), null, true); } + @Test + @TestMetadata("AnnotationWithEnum.kt") + public void testAnnotationWithEnum() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.kt"); + } + @Test @TestMetadata("BasicWithAnnotatedJava.kt") public void testBasicWithAnnotatedJava() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index 0e11e04ab91..92d100b2696 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -5003,6 +5003,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k"), Pattern.compile("^([^.]+)\\.kt$"), null, true); } + @Test + @TestMetadata("AnnotationWithEnum.kt") + public void testAnnotationWithEnum() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.kt"); + } + @Test @TestMetadata("BasicWithAnnotatedJava.kt") public void testBasicWithAnnotatedJava() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt index 1cd15bfa568..5b6a73afb14 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaSymbolProvider.kt @@ -148,6 +148,7 @@ class JavaSymbolProvider( override fun getClassLikeSymbolByFqName(classId: ClassId): FirRegularClassSymbol? { return try { + if (!hasTopLevelClassOf(classId)) return null getFirJavaClass(classId) } catch (e: ProcessCanceledException) { null @@ -155,7 +156,9 @@ class JavaSymbolProvider( } fun getFirJavaClass(classId: ClassId, content: KotlinClassFinder.Result.ClassFileContent? = null): FirRegularClassSymbol? { - if (!hasTopLevelClassOf(classId)) return null + // Enforce loading of outer class first + classId.outerClassId?.let { getFirJavaClass(it) } + return classCache.getValue(classId, content) } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index e5c70c26226..3e4382f96b6 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -5003,6 +5003,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k"), Pattern.compile("^([^.]+)\\.kt$"), null, true); } + @Test + @TestMetadata("AnnotationWithEnum.kt") + public void testAnnotationWithEnum() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/AnnotationWithEnum.kt"); + } + @Test @TestMetadata("BasicWithAnnotatedJava.kt") public void testBasicWithAnnotatedJava() throws Exception {