[FE 1.0] Report WRONG_ANNOTATION_TARGET on annotations on type arguments

^KT-47772 Fixed
This commit is contained in:
Dmitriy Novozhilov
2021-07-19 11:09:02 +03:00
committed by teamcityserver
parent 046d886850
commit c304363aea
7 changed files with 68 additions and 0 deletions
@@ -2136,6 +2136,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt46173.kt");
}
@Test
@TestMetadata("kt47772.kt")
public void testKt47772() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt47772.kt");
}
@Test
@TestMetadata("kt8325.kt")
public void testKt8325() throws Exception {
@@ -2136,6 +2136,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt46173.kt");
}
@Test
@TestMetadata("kt47772.kt")
public void testKt47772() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt47772.kt");
}
@Test
@TestMetadata("kt8325.kt")
public void testKt8325() throws Exception {
@@ -101,6 +101,12 @@ class AnnotationChecker(
fun checkExpression(expression: KtExpression, trace: BindingTrace) {
checkEntries(expression.getAnnotationEntries(), getActualTargetList(expression, null, trace.bindingContext), trace)
if (expression is KtCallElement && languageVersionSettings.supportsFeature(ProperCheckAnnotationsTargetInTypeUsePositions)) {
val typeArguments = expression.typeArguments.mapNotNull { it.typeReference }
for (typeArgument in typeArguments) {
checkEntries(typeArgument.annotationEntries, getActualTargetList(typeArgument, null, trace.bindingContext), trace)
}
}
if (expression is KtLambdaExpression) {
for (parameter in expression.valueParameters) {
parameter.typeReference?.let { check(it, trace) }
@@ -0,0 +1,19 @@
// FIR_IDENTICAL
// LANGUAGE: +ProperCheckAnnotationsTargetInTypeUsePositions
// ISSUE: KT-47772
@Target(AnnotationTarget.CLASS)
annotation class Bad
@Target(AnnotationTarget.TYPE)
annotation class Good
fun <K> materialize(): K? = null
fun test_error() {
materialize<<!WRONG_ANNOTATION_TARGET!>@Bad<!> String>()
}
fun test_ok() {
materialize<@Good String>()
}
@@ -0,0 +1,19 @@
package
public fun </*0*/ K> materialize(): K?
public fun test_error(): kotlin.Unit
public fun test_ok(): kotlin.Unit
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS}) public final annotation class Bad : kotlin.Annotation {
public constructor Bad()
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.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class Good : kotlin.Annotation {
public constructor Good()
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
}
@@ -2142,6 +2142,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt46173.kt");
}
@Test
@TestMetadata("kt47772.kt")
public void testKt47772() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt47772.kt");
}
@Test
@TestMetadata("kt8325.kt")
public void testKt8325() throws Exception {
@@ -2136,6 +2136,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt46173.kt");
}
@Test
@TestMetadata("kt47772.kt")
public void testKt47772() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt47772.kt");
}
@Test
@TestMetadata("kt8325.kt")
public void testKt8325() throws Exception {