[FE] Don't report cycle on annotation parameters if argument is vararg or array
^KT-52742 Fixed ^KT-47932
This commit is contained in:
committed by
teamcity
parent
4775855fd7
commit
12ce433bc2
+6
@@ -1188,6 +1188,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/cycleInParameters_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cycleInParameters_array.kt")
|
||||
public void testCycleInParameters_array() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/cycleInParameters_array.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cycleInParameters_before.kt")
|
||||
public void testCycleInParameters_before() throws Exception {
|
||||
|
||||
+6
@@ -1188,6 +1188,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/cycleInParameters_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cycleInParameters_array.kt")
|
||||
public void testCycleInParameters_array() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/cycleInParameters_array.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cycleInParameters_before.kt")
|
||||
public void testCycleInParameters_before() throws Exception {
|
||||
|
||||
+6
@@ -1188,6 +1188,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/cycleInParameters_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cycleInParameters_array.kt")
|
||||
public void testCycleInParameters_array() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/cycleInParameters_array.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cycleInParameters_before.kt")
|
||||
public void testCycleInParameters_before() throws Exception {
|
||||
|
||||
+1
@@ -192,6 +192,7 @@ object FirAnnotationClassDeclarationChecker : FirRegularClassChecker() {
|
||||
fun parameterHasCycle(ownedAnnotation: FirRegularClassSymbol, parameter: FirValueParameterSymbol): Boolean {
|
||||
val returnType = parameter.resolvedReturnTypeRef.coneType
|
||||
return when {
|
||||
parameter.isVararg || returnType.isNonPrimitiveArray -> false
|
||||
returnType.typeArguments.isNotEmpty() -> {
|
||||
if (returnType.classId == StandardClassIds.KClass) return false
|
||||
for (argument in returnType.typeArguments) {
|
||||
|
||||
+3
-1
@@ -13,7 +13,9 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.CYCLE_IN_ANNOTATION_PARAMETER
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.isArrayOrNullableArray
|
||||
|
||||
object CyclicAnnotationsChecker : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
@@ -52,6 +54,7 @@ object CyclicAnnotationsChecker : DeclarationChecker {
|
||||
fun parameterHasCycle(ownedAnnotation: ClassDescriptor, parameterDescriptor: ValueParameterDescriptor): Boolean {
|
||||
val returnType = parameterDescriptor.returnType?.unwrap() ?: return false
|
||||
return when {
|
||||
parameterDescriptor.isVararg || returnType.isArrayOrNullableArray() -> false
|
||||
returnType.arguments.isNotEmpty() && !ReflectionTypes.isKClassType(returnType) -> {
|
||||
for (argument in returnType.arguments) {
|
||||
if (!argument.isStarProjection) {
|
||||
@@ -83,4 +86,3 @@ object CyclicAnnotationsChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class X(<!CYCLE_IN_ANNOTATION_PARAMETER_ERROR!>val value: X<!>) // error
|
||||
annotation class Y(<!CYCLE_IN_ANNOTATION_PARAMETER_ERROR!>val value: Array<Y><!>) // error
|
||||
annotation class Y(val value: Array<Y>) //no error
|
||||
|
||||
annotation class Z1(<!CYCLE_IN_ANNOTATION_PARAMETER_ERROR!>val a: Z2<!>, <!CYCLE_IN_ANNOTATION_PARAMETER_ERROR!>val b: Z2<!>) // error
|
||||
annotation class Z2(<!CYCLE_IN_ANNOTATION_PARAMETER_ERROR!>val value: Z1<!>) // error
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// FIR_IDENTICAL
|
||||
// LANGUAGE: +ProhibitCyclesInAnnotations
|
||||
// ISSUE: KT-52742
|
||||
|
||||
annotation class AnnotationWithArray(
|
||||
val array: Array<AnnotationWithArray>
|
||||
)
|
||||
|
||||
annotation class AnnotationWithVararg(
|
||||
vararg val args: AnnotationWithVararg
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
package
|
||||
|
||||
public final annotation class AnnotationWithArray : kotlin.Annotation {
|
||||
public constructor AnnotationWithArray(/*0*/ array: kotlin.Array<AnnotationWithArray>)
|
||||
public final val array: kotlin.Array<AnnotationWithArray>
|
||||
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
|
||||
}
|
||||
|
||||
public final annotation class AnnotationWithVararg : kotlin.Annotation {
|
||||
public constructor AnnotationWithVararg(/*0*/ vararg args: AnnotationWithVararg /*kotlin.Array<out AnnotationWithVararg>*/)
|
||||
public final val args: kotlin.Array<out AnnotationWithVararg>
|
||||
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
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class X(<!CYCLE_IN_ANNOTATION_PARAMETER_WARNING!>val value: X<!>) // error
|
||||
annotation class Y(<!CYCLE_IN_ANNOTATION_PARAMETER_WARNING!>val value: Array<Y><!>) // error
|
||||
annotation class Y(val value: Array<Y>) // no error
|
||||
|
||||
annotation class Z1(<!CYCLE_IN_ANNOTATION_PARAMETER_WARNING!>val a: Z2<!>, <!CYCLE_IN_ANNOTATION_PARAMETER_WARNING!>val b: Z2<!>) // error
|
||||
annotation class Z2(<!CYCLE_IN_ANNOTATION_PARAMETER_WARNING!>val value: Z1<!>) // error
|
||||
|
||||
+1
-2
@@ -28,9 +28,8 @@ annotation class C5(val value: Array<A5>, val irrelevant: String)
|
||||
annotation class A6
|
||||
annotation class C6(val irrelevant: Double, val value: Array<A6> = [])
|
||||
|
||||
// Should be an error after fixing KT-47932.
|
||||
@R(A7::class)
|
||||
annotation class A7(<!CYCLE_IN_ANNOTATION_PARAMETER_WARNING!>val value: Array<A7><!>)
|
||||
annotation class A7(val value: Array<A7>)
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -28,9 +28,8 @@ annotation class C5(val value: Array<A5>, val irrelevant: String)
|
||||
annotation class A6
|
||||
annotation class C6(val irrelevant: Double, val value: Array<A6> = [])
|
||||
|
||||
// Should be an error after fixing KT-47932.
|
||||
@R(A7::class)
|
||||
annotation class A7(<!CYCLE_IN_ANNOTATION_PARAMETER_WARNING!>val value: Array<A7><!>)
|
||||
annotation class A7(val value: Array<A7>)
|
||||
|
||||
|
||||
|
||||
|
||||
Generated
+6
@@ -1188,6 +1188,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/cycleInParameters_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cycleInParameters_array.kt")
|
||||
public void testCycleInParameters_array() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/cycleInParameters_array.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cycleInParameters_before.kt")
|
||||
public void testCycleInParameters_before() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user