diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 67dba8d9f27..ca34aebe711 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -996,6 +996,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.kt"); } + @Test + @TestMetadata("AnnotatedBlock.kt") + public void testAnnotatedBlock() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.kt"); + } + @Test @TestMetadata("AnnotatedConstructor.kt") public void testAnnotatedConstructor() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 8f162dde7fe..556d9698867 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -996,6 +996,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.kt"); } + @Test + @TestMetadata("AnnotatedBlock.kt") + public void testAnnotatedBlock() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.kt"); + } + @Test @TestMetadata("AnnotatedConstructor.kt") public void testAnnotatedConstructor() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 76ba3f4a97f..9cdb0e13770 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -996,6 +996,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.kt"); } + @Test + @TestMetadata("AnnotatedBlock.kt") + public void testAnnotatedBlock() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.kt"); + } + @Test @TestMetadata("AnnotatedConstructor.kt") public void testAnnotatedConstructor() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionAnnotationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionAnnotationChecker.kt index aa07ecd5302..1089faa19e0 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionAnnotationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionAnnotationChecker.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression import org.jetbrains.kotlin.KtFakeSourceElementKind +import org.jetbrains.kotlin.KtRealSourceElementKind import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget import org.jetbrains.kotlin.fir.analysis.checkers.checkRepeatedAnnotation @@ -29,7 +30,8 @@ object FirExpressionAnnotationChecker : FirBasicExpressionChecker() { // See KT-33658 about annotations on non-expression statements if (expression is FirDeclaration || expression !is FirExpression || - expression is FirBlock && expression.source?.kind == KtFakeSourceElementKind.DesugaredForLoop + expression is FirBlock && (expression.source?.kind == KtRealSourceElementKind || + expression.source?.kind == KtFakeSourceElementKind.DesugaredForLoop) ) return val annotations = expression.annotations diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.fir.txt b/compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.fir.txt new file mode 100644 index 00000000000..4b18b936f46 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.fir.txt @@ -0,0 +1,28 @@ +FILE: AnnotatedBlock.kt + public final annotation class Ann : R|kotlin/Annotation| { + public constructor(): R|Ann| { + super() + } + + } + public final annotation class Ann2 : R|kotlin/Annotation| { + public constructor(): R|Ann2| { + super() + } + + } + public final fun test(x: R|kotlin/String?|): R|kotlin/Unit| { + when () { + !=(R|/x|, Null(null)) -> @R|Ann|() @R|Ann2|() { + Q|kotlin/Unit| + } + } + + when () { + !=(R|/x|, Null(null)) -> { + @R|Ann|() @R|Ann2|() Q|kotlin/Unit| + } + } + + @R|Ann|() @R|Ann2|() R|/x| + } diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.kt new file mode 100644 index 00000000000..7b30f955d2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.kt @@ -0,0 +1,10 @@ +// FIR_IDENTICAL +// FIR_DUMP +// ISSUE: KT-52175 + +annotation class Ann + +fun test(x: String?) { + if (x != null) + @Ann() { Unit } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.txt b/compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.txt new file mode 100644 index 00000000000..e41d31997ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.txt @@ -0,0 +1,10 @@ +package + +public fun test(/*0*/ x: kotlin.String?): kotlin.Unit + +public final annotation class Ann : kotlin.Annotation { + public constructor Ann() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index c438b7f364a..6c9d2da3bb4 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -996,6 +996,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.kt"); } + @Test + @TestMetadata("AnnotatedBlock.kt") + public void testAnnotatedBlock() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/AnnotatedBlock.kt"); + } + @Test @TestMetadata("AnnotatedConstructor.kt") public void testAnnotatedConstructor() throws Exception {