diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/recursiveNamedAnnotation.kt b/compiler/fir/analysis-tests/testData/resolve/problems/recursiveNamedAnnotation.kt new file mode 100644 index 00000000000..71fd5b93b63 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/problems/recursiveNamedAnnotation.kt @@ -0,0 +1,20 @@ +// FILE: AliasFor.java + +public @interface AliasFor { + @AliasFor(value = "attribute") + String value() default ""; + + @AliasFor(value = "value") + String attribute() default ""; +} + +// FILE: Service.java +public @interface Service { + @AliasFor(value = "component") + String value() default ""; +} + +// FILE: Annotated.kt + +@Service(value = "Your") +class My \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/recursiveNamedAnnotation.txt b/compiler/fir/analysis-tests/testData/resolve/problems/recursiveNamedAnnotation.txt new file mode 100644 index 00000000000..46ecee2487f --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/problems/recursiveNamedAnnotation.txt @@ -0,0 +1,7 @@ +FILE: Annotated.kt + @R|Service|(value = String(Your)) public final class My : R|kotlin/Any| { + public constructor(): R|My| { + super() + } + + } diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 23c8183147d..39cc95f6058 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -2079,6 +2079,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/problems/questionableSmartCast.kt"); } + @TestMetadata("recursiveNamedAnnotation.kt") + public void testRecursiveNamedAnnotation() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/problems/recursiveNamedAnnotation.kt"); + } + @TestMetadata("safeCallInvoke.kt") public void testSafeCallInvoke() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/problems/safeCallInvoke.kt"); diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 59c78f4a0d2..ccb0b49c2ac 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -2079,6 +2079,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/problems/questionableSmartCast.kt"); } + @TestMetadata("recursiveNamedAnnotation.kt") + public void testRecursiveNamedAnnotation() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/problems/recursiveNamedAnnotation.kt"); + } + @TestMetadata("safeCallInvoke.kt") public void testSafeCallInvoke() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/problems/safeCallInvoke.kt"); diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index a3bc2533eec..71463b1001f 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -2079,6 +2079,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract runTest("compiler/fir/analysis-tests/testData/resolve/problems/questionableSmartCast.kt"); } + @TestMetadata("recursiveNamedAnnotation.kt") + public void testRecursiveNamedAnnotation() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/problems/recursiveNamedAnnotation.kt"); + } + @TestMetadata("safeCallInvoke.kt") public void testSafeCallInvoke() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/problems/safeCallInvoke.kt"); 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 d93fa5c690c..9da1b4d0ca2 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 @@ -168,6 +168,7 @@ class JavaSymbolProvider( javaTypeParameterStack.addStack(parentStack) } } + val methodMap = mutableMapOf() val firJavaClass = buildJavaClass { source = (javaClass as? JavaElementImpl<*>)?.psi?.toFirPsiSourceElement() session = this@JavaSymbolProvider.session @@ -219,7 +220,9 @@ class JavaSymbolProvider( classIsAnnotation, valueParametersForAnnotationConstructor, dispatchReceiver - ) + ).apply { + methodMap[javaMethod] = this + } } val javaClassDeclaredConstructors = javaClass.constructors val constructorId = CallableId(classId.packageFqName, classId.relativeClassName, classId.shortClassName) @@ -270,6 +273,10 @@ class JavaSymbolProvider( } ) firJavaClass.addAnnotationsFrom(this@JavaSymbolProvider.session, javaClass, javaTypeParameterStack) + // NB: this is done here to unbind possible annotation cycle + for ((javaMethod, firJavaMethod) in methodMap) { + firJavaMethod.annotations.addAnnotationsFrom(session, javaMethod, javaTypeParameterStack) + } return firJavaClass } @@ -364,7 +371,6 @@ class JavaSymbolProvider( returnTypeRef = returnType.toFirJavaTypeRef(this@JavaSymbolProvider.session, javaTypeParameterStack) isStatic = javaMethod.isStatic typeParameters += javaMethod.typeParameters.convertTypeParameters(javaTypeParameterStack) - addAnnotationsFrom(this@JavaSymbolProvider.session, javaMethod, javaTypeParameterStack) for ((index, valueParameter) in javaMethod.valueParameters.withIndex()) { valueParameters += valueParameter.toFirValueParameter( this@JavaSymbolProvider.session, index, javaTypeParameterStack, diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt index eceb8318ba9..2d2d248a400 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt @@ -485,7 +485,7 @@ internal fun FirJavaClass.addAnnotationsFrom( annotations.addAnnotationsFrom(session, javaAnnotationOwner, javaTypeParameterStack) } -private fun MutableList.addAnnotationsFrom( +internal fun MutableList.addAnnotationsFrom( session: FirSession, javaAnnotationOwner: JavaAnnotationOwner, javaTypeParameterStack: JavaTypeParameterStack diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index e95c41dfedd..c4bbcb442e3 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -5461,11 +5461,6 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest public void testAllFilesPresentInBigArity() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/functions/bigArity"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } - - @TestMetadata("nestedBigArityFunCalls.kt") - public void testNestedBigArityFunCalls() throws Exception { - runTest("compiler/testData/codegen/box/functions/bigArity/nestedBigArityFunCalls.kt"); - } } @TestMetadata("compiler/testData/codegen/box/functions/functionExpression")