Report EXPERIMENTAL_ANNOTATION_ON_WRONG_TARGET without explicit @Target

#KT-48349 Fixed
This commit is contained in:
Mikhail Glukhikh
2021-08-20 20:07:18 +03:00
committed by TeamCityServer
parent 865fccdd29
commit 7b0e5927cb
8 changed files with 102 additions and 1 deletions
@@ -35426,6 +35426,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
public void testWasExperimental() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/wasExperimental.kt");
}
@Test
@TestMetadata("wrongTargetsWithoutExplicitTarget.kt")
public void testWrongTargetsWithoutExplicitTarget() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/wrongTargetsWithoutExplicitTarget.kt");
}
}
@Nested
@@ -35426,6 +35426,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
public void testWasExperimental() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/wasExperimental.kt");
}
@Test
@TestMetadata("wrongTargetsWithoutExplicitTarget.kt")
public void testWrongTargetsWithoutExplicitTarget() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/wrongTargetsWithoutExplicitTarget.kt");
}
}
@Nested
@@ -59,7 +59,8 @@ class ExperimentalMarkerDeclarationAnnotationChecker(private val module: ModuleD
}
val annotationClass = annotation.annotationClass ?: continue
if (annotationClass.annotations.any { it.fqName in OptInNames.EXPERIMENTAL_FQ_NAMES }) {
val possibleTargets = AnnotationChecker.applicableTargetSet(annotationClass).orEmpty().intersect(actualTargets)
val applicableTargets = AnnotationChecker.applicableTargetSet(annotationClass) ?: KotlinTarget.DEFAULT_TARGET_SET
val possibleTargets = applicableTargets.intersect(actualTargets)
val annotationUseSiteTarget = entry.useSiteTarget?.getAnnotationUseSiteTarget()
if (PROPERTY_GETTER in possibleTargets ||
annotationUseSiteTarget == AnnotationUseSiteTarget.PROPERTY_GETTER
@@ -0,0 +1,25 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
@RequiresOptIn
annotation class SomeOptInMarker
@RequiresOptIn
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.PROPERTY, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.LOCAL_VARIABLE)
annotation class OtherOptInMarker
class IntWrapper(
@SomeOptInMarker
@OtherOptInMarker
val value: Int
) {
val isEven: Boolean
@SomeOptInMarker
@OtherOptInMarker
get() = (value % 2) == 0
}
fun foo() {
@SomeOptInMarker
@OtherOptInMarker
val value = 2
}
@@ -0,0 +1,25 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
@RequiresOptIn
annotation class SomeOptInMarker
@RequiresOptIn
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.PROPERTY, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.LOCAL_VARIABLE)
annotation class OtherOptInMarker
class IntWrapper(
<!EXPERIMENTAL_ANNOTATION_ON_WRONG_TARGET!>@SomeOptInMarker<!>
<!EXPERIMENTAL_ANNOTATION_ON_WRONG_TARGET!>@OtherOptInMarker<!>
val value: Int
) {
val isEven: Boolean
<!EXPERIMENTAL_ANNOTATION_ON_WRONG_TARGET!>@SomeOptInMarker<!>
<!EXPERIMENTAL_ANNOTATION_ON_WRONG_TARGET!>@OtherOptInMarker<!>
get() = (value % 2) == 0
}
fun foo() {
<!EXPERIMENTAL_ANNOTATION_ON_WRONG_TARGET!>@SomeOptInMarker<!>
<!EXPERIMENTAL_ANNOTATION_ON_WRONG_TARGET!>@OtherOptInMarker<!>
val value = 2
}
@@ -0,0 +1,26 @@
package
public fun foo(): kotlin.Unit
public final class IntWrapper {
public constructor IntWrapper(/*0*/ @SomeOptInMarker @OtherOptInMarker value: kotlin.Int)
@get:SomeOptInMarker @get:OtherOptInMarker public final val isEven: kotlin.Boolean
public final val value: kotlin.Int
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
}
@kotlin.RequiresOptIn @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.PROPERTY, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.LOCAL_VARIABLE}) public final annotation class OtherOptInMarker : kotlin.Annotation {
public constructor OtherOptInMarker()
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
}
@kotlin.RequiresOptIn public final annotation class SomeOptInMarker : kotlin.Annotation {
public constructor SomeOptInMarker()
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
}
@@ -35522,6 +35522,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
public void testWasExperimental() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/wasExperimental.kt");
}
@Test
@TestMetadata("wrongTargetsWithoutExplicitTarget.kt")
public void testWrongTargetsWithoutExplicitTarget() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/wrongTargetsWithoutExplicitTarget.kt");
}
}
@Nested
@@ -35426,6 +35426,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
public void testWasExperimental() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/wasExperimental.kt");
}
@Test
@TestMetadata("wrongTargetsWithoutExplicitTarget.kt")
public void testWrongTargetsWithoutExplicitTarget() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/wrongTargetsWithoutExplicitTarget.kt");
}
}
@Nested