[FIR] KT-57247: Expand typealiases in annotation vararg arguments

^KT-57247 Fixed
This commit is contained in:
Nikolay Lunyak
2023-03-10 14:42:19 +02:00
committed by Space Team
parent 5b0b7c4da4
commit 4b8471d806
6 changed files with 33 additions and 5 deletions
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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
@@ -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
@@ -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 {