diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index a1b6899f097..fbc506e323a 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -4870,6 +4870,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/removeOnAbstractMap.kt"); } + @Test + @TestMetadata("repeatedAnnotations.kt") + public void testRepeatedAnnotations() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.kt"); + } + @Test @TestMetadata("runOnIntegerLiteral.kt") public void testRunOnIntegerLiteral() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.fir.txt new file mode 100644 index 00000000000..e28909546c0 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.fir.txt @@ -0,0 +1,33 @@ +FILE: test.kt + public final fun foo(bar: R|() -> T|): R|kotlin/Unit| { + } + @R|kotlin/annotation/Target|(allowedTargets = vararg(Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.TYPE|)) public final annotation class Ann : R|kotlin/Annotation| { + public constructor(): R|Ann| { + super() + } + + } + public final fun baz(): R|@R|Ann|() @R|Ann|() kotlin/String| { + ^baz String(12) + } + public final fun qux(): R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!| { + ^qux Q|Some|.R|/Some.foo|().R|SubstitutionOverride|(Int(0)) + } + public final fun test(): R|kotlin/Unit| { + R|/foo|(foo@fun (): R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!| { + ^ Q|Some|.R|/Some.foo|().R|SubstitutionOverride|(Int(0)) + } + ) + R|/foo|(foo@fun (): R|@R|Ann|() @R|Ann|() kotlin/String| { + ^ R|/baz|() + } + ) + R|/foo|(foo@fun (): R|@R|SomeAnn|(value = Int(1)) @R|SomeAnn|(value = Int(2)) kotlin/String!| { + ^ R|/qux|() + } + ) + R|/foo|(fun (): R|@R|Ann|() @R|Ann|() kotlin/String| { + ^@foo String() + } + ) + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.kt new file mode 100644 index 00000000000..316d7798952 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.kt @@ -0,0 +1,37 @@ +// FILE: Some.java +import java.util.List; + +public class Some { + public static List<@SomeAnn(1) @SomeAnn(2) String> foo() { + return null; + } +} + +// FILE: SomeAnn.java + +@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) +public @interface SomeAnn { + int value(); +} + + +// FILE: test.kt +fun foo(bar: () -> T) { + +} + +@Target(AnnotationTarget.TYPE) +annotation class Ann + +fun baz(): @Ann @Ann String = "12" +fun qux() = Some.foo()[0] + +fun test() { + foo({ Some.foo()[0] }) + foo({ baz() }) + foo({ qux() }) + foo(fun(): @Ann @Ann String { + return "" + }) +} + 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 c04107b8996..653ab068b61 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 @@ -4870,6 +4870,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/removeOnAbstractMap.kt"); } + @Test + @TestMetadata("repeatedAnnotations.kt") + public void testRepeatedAnnotations() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.kt"); + } + @Test @TestMetadata("runOnIntegerLiteral.kt") public void testRunOnIntegerLiteral() 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 334d7685fdd..b4982edab54 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 @@ -4870,6 +4870,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/removeOnAbstractMap.kt"); } + @Test + @TestMetadata("repeatedAnnotations.kt") + public void testRepeatedAnnotations() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/repeatedAnnotations.kt"); + } + @Test @TestMetadata("runOnIntegerLiteral.kt") public void testRunOnIntegerLiteral() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationChecker.kt index f6d3199ca28..23f15d629a8 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationChecker.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration import org.jetbrains.kotlin.KtFakeSourceElementKind +import org.jetbrains.kotlin.KtRealSourceElementKind import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.* @@ -70,7 +71,7 @@ object FirAnnotationChecker : FirBasicDeclarationChecker() { if (declaration is FirProperty) { checkRepeatedAnnotationsInProperty(declaration, context, reporter) } else if (declaration is FirCallableDeclaration) { - if (declaration.source?.kind !is KtFakeSourceElementKind) { + if (declaration.source?.kind is KtRealSourceElementKind && declaration.returnTypeRef.source?.kind is KtRealSourceElementKind) { checkRepeatedAnnotations(declaration.returnTypeRef.coneTypeSafe(), context, reporter) } } else if (declaration is FirTypeAlias) {