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 dec40b90f98..1c458873a1d 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 @@ -57,6 +57,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true); } + @Test + @TestMetadata("annotationArgumentWithAliasedArrayType.kt") + public void testAnnotationArgumentWithAliasedArrayType() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotationArgumentWithAliasedArrayType.kt"); + } + @Test @TestMetadata("AnonymousInitializerVarAndConstructor.kt") public void testAnonymousInitializerVarAndConstructor() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index a31fa9d4673..594e94e1d47 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -57,6 +57,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true); } + @Test + @TestMetadata("annotationArgumentWithAliasedArrayType.kt") + public void testAnnotationArgumentWithAliasedArrayType() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotationArgumentWithAliasedArrayType.kt"); + } + @Test @TestMetadata("AnonymousInitializerVarAndConstructor.kt") public void testAnonymousInitializerVarAndConstructor() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 247f1188e13..77cb54f9e4b 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -57,6 +57,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true); } + @Test + @TestMetadata("annotationArgumentWithAliasedArrayType.kt") + public void testAnnotationArgumentWithAliasedArrayType() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotationArgumentWithAliasedArrayType.kt"); + } + @Test @TestMetadata("AnonymousInitializerVarAndConstructor.kt") public void testAnonymousInitializerVarAndConstructor() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationClassDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationClassDeclarationChecker.kt index 141c18b791d..987515c81ae 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationClassDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirAnnotationClassDeclarationChecker.kt @@ -101,7 +101,7 @@ object FirAnnotationClassDeclarationChecker : FirRegularClassChecker() { // DO NOTHING: arrays of unsigned types are allowed } classId == StandardClassIds.Array -> { - if (!isAllowedArray(typeRef, context.session)) + if (!isAllowedArray(coneType, context.session)) reporter.reportOn(typeRef.source, FirErrors.INVALID_TYPE_OF_ANNOTATION_MEMBER, context) } isAllowedClassKind(coneType, context.session) -> { @@ -137,13 +137,12 @@ object FirAnnotationClassDeclarationChecker : FirRegularClassChecker() { return typeRefClassKind == ANNOTATION_CLASS || typeRefClassKind == ENUM_CLASS } - private fun isAllowedArray(typeRef: FirTypeRef, session: FirSession): Boolean { - val typeArguments = typeRef.coneType.typeArguments + private fun isAllowedArray(type: ConeKotlinType, session: FirSession): Boolean { + val typeArguments = type.typeArguments if (typeArguments.size != 1) return false - val arrayType = (typeArguments[0] as? ConeKotlinTypeProjection) - ?.type + val arrayType = (typeArguments[0] as? ConeKotlinTypeProjection)?.type?.fullyExpandedType(session) ?: return false if (arrayType.isNullable) return false diff --git a/compiler/testData/diagnostics/tests/annotationArgumentWithAliasedArrayType.kt b/compiler/testData/diagnostics/tests/annotationArgumentWithAliasedArrayType.kt new file mode 100644 index 00000000000..5a092851f07 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotationArgumentWithAliasedArrayType.kt @@ -0,0 +1,5 @@ +// FIR_IDENTICAL +// ISSUE: KT-57247 + +typealias Aliased = String +annotation class Tag(vararg val tags: Aliased) // K1: ok, K2: INVALID_TYPE_OF_ANNOTATION_MEMBER 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 2e4354b3986..7d62b8a1ad9 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 @@ -57,6 +57,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true); } + @Test + @TestMetadata("annotationArgumentWithAliasedArrayType.kt") + public void testAnnotationArgumentWithAliasedArrayType() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotationArgumentWithAliasedArrayType.kt"); + } + @Test @TestMetadata("AnonymousInitializerVarAndConstructor.kt") public void testAnonymousInitializerVarAndConstructor() throws Exception {