FIR: report WRONG_ANNOTATION_TARGET on types
This commit is contained in:
Vendored
+1
-1
@@ -5,7 +5,7 @@ interface I {
|
||||
}
|
||||
|
||||
class A {
|
||||
fun too(): @<!NOT_AN_ANNOTATION_CLASS!>Annotation<!> Unit {}
|
||||
fun too(): <!WRONG_ANNOTATION_TARGET!>@<!NOT_AN_ANNOTATION_CLASS!>Annotation<!><!> Unit {}
|
||||
|
||||
fun foo(): <!REDUNDANT_RETURN_UNIT_TYPE!>Unit<!>
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ abstract class First {
|
||||
}
|
||||
|
||||
@WithString("xyz")
|
||||
class Second(val y: Char) : @WithInt(0) First() {
|
||||
class Second(val y: Char) : <!WRONG_ANNOTATION_TARGET!>@WithInt(0)<!> First() {
|
||||
override fun foo(arg: Double) {
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.FirAnnotatedDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
|
||||
@@ -40,12 +41,14 @@ private val defaultAnnotationTargets = KotlinTarget.DEFAULT_TARGET_SET
|
||||
|
||||
fun FirAnnotationCall.getAllowedAnnotationTargets(session: FirSession): Set<KotlinTarget> {
|
||||
if (annotationTypeRef is FirErrorTypeRef) return KotlinTarget.values().toSet()
|
||||
val annotationClass = (this.annotationTypeRef.coneType as? ConeClassLikeType)?.lookupTag?.toSymbol(session)?.fir as? FirRegularClass
|
||||
val annotationClass = (this.annotationTypeRef.coneType as? ConeClassLikeType)
|
||||
?.fullyExpandedType(session)?.lookupTag?.toSymbol(session)?.fir as? FirRegularClass
|
||||
return annotationClass?.getAllowedAnnotationTargets() ?: defaultAnnotationTargets
|
||||
}
|
||||
|
||||
fun FirRegularClass.getAllowedAnnotationTargets(): Set<KotlinTarget> {
|
||||
val targetAnnotation = getTargetAnnotation() ?: return defaultAnnotationTargets
|
||||
if (targetAnnotation.argumentList.arguments.isEmpty()) return emptySet()
|
||||
val arguments = when (val targetArgument = targetAnnotation.findSingleArgumentByName(TARGET_PARAMETER_NAME)) {
|
||||
is FirVarargArgumentsExpression -> targetArgument.arguments
|
||||
is FirArrayOfCall -> targetArgument.arguments
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.type
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.getAllowedAnnotationTargets
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.withSuppressedDiagnostics
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
|
||||
object FirTypeAnnotationChecker : FirTypeRefChecker() {
|
||||
override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
for (annotation in typeRef.annotations) {
|
||||
withSuppressedDiagnostics(annotation, context) {
|
||||
val annotationTargets = annotation.getAllowedAnnotationTargets(context.session)
|
||||
if (KotlinTarget.TYPE !in annotationTargets) {
|
||||
val useSiteTarget = annotation.useSiteTarget
|
||||
if (useSiteTarget == null || KotlinTarget.USE_SITE_MAPPING[useSiteTarget] !in annotationTargets) {
|
||||
reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "type usage", context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -171,6 +171,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
||||
if (resolvedTypeRef.type is ConeClassErrorType) {
|
||||
super.visitResolvedTypeRef(resolvedTypeRef, data)
|
||||
}
|
||||
if (resolvedTypeRef.source?.kind is FirFakeSourceElementKind) return
|
||||
resolvedTypeRef.delegatedTypeRef?.accept(this, data)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,18 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.checkers
|
||||
|
||||
import org.jetbrains.kotlin.fir.analysis.cfa.AbstractFirPropertyInitializationChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.cfa.FirCallsEffectAnalyzer
|
||||
import org.jetbrains.kotlin.fir.analysis.cfa.FirPropertyInitializationAnalyzer
|
||||
import org.jetbrains.kotlin.fir.analysis.cfa.FirReturnsImpliesAnalyzer
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.cfa.FirControlFlowChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.*
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.type.FirSuspendModifierChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.type.FirTypeAnnotationChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.type.FirTypeRefChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.type.TypeCheckers
|
||||
|
||||
object CommonTypeCheckers : TypeCheckers() {
|
||||
override val typeRefCheckers: Set<FirTypeRefChecker> = setOf(
|
||||
FirSuspendModifierChecker
|
||||
FirTypeAnnotationChecker,
|
||||
FirSuspendModifierChecker,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -323,7 +323,8 @@ private fun FirTypeRef.hideLocalTypeIfNeeded(
|
||||
}
|
||||
val superType = firClass.superTypeRefs.single()
|
||||
if (superType is FirResolvedTypeRef) {
|
||||
return superType
|
||||
val newKind = source?.kind
|
||||
return if (newKind is FirFakeSourceElementKind) superType.copyWithNewSourceKind(newKind) else superType
|
||||
}
|
||||
}
|
||||
return this
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
annotation class My
|
||||
|
||||
fun foo(arg: Int): Int {
|
||||
try {
|
||||
return 1 / (arg - arg)
|
||||
} catch (e: <!WRONG_ANNOTATION_TARGET!>@My<!> Exception) {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// FIR_IDENTICAL
|
||||
annotation class My
|
||||
|
||||
fun foo(arg: Int): Int {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ fun inParamNested(fn1: (fn2: (@Ann n: Int)->Unit)->Unit) {}
|
||||
|
||||
fun inReturn(): (@Ann x: Int)->Unit = {}
|
||||
|
||||
class A : (@Ann Int)->Unit {
|
||||
class A : (<!WRONG_ANNOTATION_TARGET!>@Ann<!> Int)->Unit {
|
||||
override fun invoke(p1: Int) {
|
||||
var lambda: (@Ann x: Int)->Unit = {}
|
||||
}
|
||||
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
//!DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class a
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class b(val i: Int)
|
||||
|
||||
annotation class c
|
||||
|
||||
fun foo(i: @a Int?) {}
|
||||
|
||||
fun foo(l: List<@a Int?>) {}
|
||||
|
||||
fun @a Int?.bar() {}
|
||||
|
||||
val baz: @a Int? = 1
|
||||
|
||||
|
||||
fun foo1(i: @b(1) Int?) {}
|
||||
|
||||
fun foo1(l: List<@b(1) Int?>) {}
|
||||
|
||||
fun @b(1) Int?.bar1() {}
|
||||
|
||||
val baz1: @b(1) Int? = 1
|
||||
|
||||
|
||||
fun foo2(i: @[a b(1)] Int?) {}
|
||||
|
||||
fun foo2(l: List<@[a b(1)] Int?>) {}
|
||||
|
||||
fun @[a b(1)] Int?.bar2() {}
|
||||
|
||||
val baz2: @[a b(1)] Int? = 1
|
||||
|
||||
|
||||
fun foo3(i: @c Int?) {}
|
||||
|
||||
fun foo3(l: List<@c Int?>) {}
|
||||
|
||||
fun @c Int?.bar3() {}
|
||||
|
||||
val baz3: @c Int? = 1
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//!DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
@Target(AnnotationTarget.ANNOTATION_CLASS) annotation class base
|
||||
|
||||
@base annotation class derived
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(<!WRONG_ANNOTATION_TARGET!>@base<!> val x: Int) {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0)
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun foo(<!WRONG_ANNOTATION_TARGET!>@base<!> y: @base Int): Int {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun bar(<!WRONG_ANNOTATION_TARGET!>@base<!> z: @base Int) = z + 1
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val local = bar(y)
|
||||
return local
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
@Target(AnnotationTarget.ANNOTATION_CLASS) annotation class base
|
||||
|
||||
@base annotation class derived
|
||||
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target(AnnotationTarget.CLASS) annotation class base
|
||||
|
||||
@base annotation class derived
|
||||
|
||||
@base class correct(<!WRONG_ANNOTATION_TARGET!>@base<!> val x: Int, <!WRONG_ANNOTATION_TARGET!>@base<!> w: @base Int) {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0, 0)
|
||||
}
|
||||
|
||||
@base enum class My <!WRONG_ANNOTATION_TARGET!>@base<!> constructor() {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun foo(<!WRONG_ANNOTATION_TARGET!>@base<!> y: @base Int): Int {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun bar(<!WRONG_ANNOTATION_TARGET!>@base<!> z: @base Int) = z + 1
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val local = bar(y)
|
||||
return local
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target(AnnotationTarget.CLASS) annotation class base
|
||||
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
@Target(AnnotationTarget.CONSTRUCTOR) annotation class base
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(<!WRONG_ANNOTATION_TARGET!>@base<!> val x: Int) {
|
||||
@base constructor(): this(0)
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My @base constructor() {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun foo(<!WRONG_ANNOTATION_TARGET!>@base<!> y: @base Int): Int {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun bar(<!WRONG_ANNOTATION_TARGET!>@base<!> z: @base Int) = z + 1
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val local = bar(y)
|
||||
return local
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
@Target(AnnotationTarget.CONSTRUCTOR) annotation class base
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target() annotation class empty
|
||||
|
||||
@empty annotation class derived
|
||||
|
||||
@empty class correct(@empty val x: Int, @empty w: @empty Int) {
|
||||
@empty constructor(): this(0, 0)
|
||||
}
|
||||
|
||||
@empty enum class My @empty constructor() {
|
||||
@empty FIRST,
|
||||
@empty SECOND
|
||||
}
|
||||
|
||||
@empty fun foo(@empty y: @empty Int): Int {
|
||||
@empty fun bar(@empty z: @empty Int) = z + 1
|
||||
@empty val local = bar(y)
|
||||
return local
|
||||
}
|
||||
|
||||
@empty val z = <!WRONG_ANNOTATION_TARGET!>@empty<!> 0
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target() annotation class empty
|
||||
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
@Target(AnnotationTarget.FUNCTION) annotation class base
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(<!WRONG_ANNOTATION_TARGET!>@base<!> val x: Int) {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0)
|
||||
|
||||
@base public fun baz() {}
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My <!WRONG_ANNOTATION_TARGET!>@base<!> constructor() {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
|
||||
}
|
||||
|
||||
@base fun foo(<!WRONG_ANNOTATION_TARGET!>@base<!> y: @base Int): Int {
|
||||
@base fun bar(<!WRONG_ANNOTATION_TARGET!>@base<!> z: @base Int) = z + 1
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val local = bar(y)
|
||||
return local
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
@Target(AnnotationTarget.FUNCTION) annotation class base
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ annotation class special
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class base
|
||||
|
||||
fun transform(i: Int, tr: (@special Int) -> Int): Int = @special tr(@special i)
|
||||
fun transform(i: Int, tr: (<!WRONG_ANNOTATION_TARGET!>@special<!> Int) -> Int): Int = @special tr(@special i)
|
||||
|
||||
fun foo(i: Int): Int {
|
||||
val j = @special i + 1
|
||||
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target(AnnotationTarget.<!UNRESOLVED_REFERENCE!>INIT<!>) annotation class incorrect
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> annotation class derived
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> class correct(<!WRONG_ANNOTATION_TARGET!>@incorrect<!> val x: Int, <!WRONG_ANNOTATION_TARGET!>@incorrect<!> w: @incorrect Int) {
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> constructor(): this(0, 0)
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> enum class My <!WRONG_ANNOTATION_TARGET!>@incorrect<!> constructor() {
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> FIRST,
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> SECOND
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> fun foo(<!WRONG_ANNOTATION_TARGET!>@incorrect<!> y: @incorrect Int): Int {
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> fun bar(<!WRONG_ANNOTATION_TARGET!>@incorrect<!> z: @incorrect Int) = z + 1
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> val local = bar(y)
|
||||
return local
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> val z = <!WRONG_ANNOTATION_TARGET!>@incorrect<!> 0
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target(AnnotationTarget.<!UNRESOLVED_REFERENCE!>INIT<!>) annotation class incorrect
|
||||
|
||||
|
||||
+3
-3
@@ -64,15 +64,15 @@ import test.AnnotationTargets.*
|
||||
|
||||
@base <!WRONG_ANNOTATION_TARGET!>@meta<!> @type <!WRONG_ANNOTATION_TARGET!>@method<!> <!WRONG_ANNOTATION_TARGET!>@multiple<!> class KClass(
|
||||
@base @fieldann @parameter val y:
|
||||
@base @type Int) {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> <!WRONG_ANNOTATION_TARGET!>@type<!> Int) {
|
||||
|
||||
@base @multiple @fieldann <!WRONG_ANNOTATION_TARGET!>@local<!> val x = 0
|
||||
@method @konstructor @type get
|
||||
|
||||
@base @method @multiple <!WRONG_ANNOTATION_TARGET!>@konstructor<!>
|
||||
fun foo(@parameter <!WRONG_ANNOTATION_TARGET!>@type<!> i:
|
||||
@base @multiple Int
|
||||
): @fieldann @parameter Int {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> <!WRONG_ANNOTATION_TARGET!>@multiple<!> Int
|
||||
): <!WRONG_ANNOTATION_TARGET!>@fieldann<!> <!WRONG_ANNOTATION_TARGET!>@parameter<!> Int {
|
||||
|
||||
@local @base <!WRONG_ANNOTATION_TARGET!>@multiple<!> <!WRONG_ANNOTATION_TARGET!>@fieldann<!> val j = i + 1
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> <!WRONG_ANNOTATION_TARGET!>@multiple<!> return j
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
@Target(AnnotationTarget.LOCAL_VARIABLE) annotation class base
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(<!WRONG_ANNOTATION_TARGET!>@base<!> val x: Int) {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0)
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun foo(<!WRONG_ANNOTATION_TARGET!>@base<!> y: @base Int): Int {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun bar(<!WRONG_ANNOTATION_TARGET!>@base<!> z: @base Int) = z + 1
|
||||
@base val local = bar(y)
|
||||
return local
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
@Target(AnnotationTarget.LOCAL_VARIABLE) annotation class base
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
|
||||
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target(AnnotationTarget.PROPERTY) annotation class base
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(@base val x: Int, <!WRONG_ANNOTATION_TARGET!>@base<!> w: Int) {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0, 0)
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My {
|
||||
@base FIRST,
|
||||
@base SECOND
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun foo(<!WRONG_ANNOTATION_TARGET!>@base<!> y: @base Int): Int {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun bar(<!WRONG_ANNOTATION_TARGET!>@base<!> z: @base Int) = z + 1
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val local = bar(y)
|
||||
return local
|
||||
}
|
||||
|
||||
@base val z = 0
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target(AnnotationTarget.PROPERTY) annotation class base
|
||||
|
||||
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
annotation class base
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class typed
|
||||
|
||||
@base class My(val x: @base @typed Int, y: @base @typed Int) {
|
||||
val z: @base @typed Int = y
|
||||
fun foo(): @base @typed Int = z
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
annotation class base
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
|
||||
+2
-2
@@ -26,10 +26,10 @@ class Class2 {
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@A<!> fun foo() {}
|
||||
<!WRONG_ANNOTATION_TARGET!>@A<!> class D
|
||||
fun foo(i: @A Int) {
|
||||
fun foo(i: <!WRONG_ANNOTATION_TARGET!>@A<!> Int) {
|
||||
<!WRONG_ANNOTATION_TARGET!>@A<!> val i = 1
|
||||
}
|
||||
fun <T> test(t: @A T): T = t
|
||||
fun <T> test(t: <!WRONG_ANNOTATION_TARGET!>@A<!> T): T = t
|
||||
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
annotation class base
|
||||
|
||||
val x: List<@base String>? = null
|
||||
|
||||
val y: List<@[base] String>? = null
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class typeAnn
|
||||
|
||||
fun foo(list: List<@typeAnn Int>) = list
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
annotation class base
|
||||
|
||||
val x: List<<!WRONG_ANNOTATION_TARGET!>@base<!> String>? = null
|
||||
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER) annotation class base
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(@base val x: Int, @base w: Int) {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0, 0)
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun foo(@base y: @base Int): Int {
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> fun bar(@base z: @base Int) = z + 1
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val local = bar(y)
|
||||
return local
|
||||
}
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER) annotation class base
|
||||
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
// !LANGUAGE: +ProperCheckAnnotationsTargetInTypeUsePositions
|
||||
// ISSUE: KT-28449
|
||||
|
||||
@Target(AnnotationTarget.PROPERTY_GETTER)
|
||||
annotation class Ann
|
||||
|
||||
abstract class Foo : @Ann Any()
|
||||
|
||||
abstract class Bar<T : @Ann Any>
|
||||
|
||||
fun test_1(a: Any) {
|
||||
if (a is @Ann String) return
|
||||
}
|
||||
|
||||
open class TypeToken<T>
|
||||
val test_2 = object : TypeToken<@Ann String>() {}
|
||||
|
||||
fun test_3(a: Any) {
|
||||
a as @Ann Int
|
||||
}
|
||||
|
||||
fun <T> test_4() where T : @Ann Any, T : @Ann CharSequence {}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +ProperCheckAnnotationsTargetInTypeUsePositions
|
||||
// ISSUE: KT-28449
|
||||
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ annotation class Ann
|
||||
|
||||
class E : <!ANNOTATION_ON_SUPERCLASS!>@field:Ann<!> <!ANNOTATION_ON_SUPERCLASS!>@get:Ann<!> <!ANNOTATION_ON_SUPERCLASS!>@set:Ann<!> <!ANNOTATION_ON_SUPERCLASS!>@setparam:Ann<!> Foo
|
||||
|
||||
interface G : @Ann Foo
|
||||
interface G : <!WRONG_ANNOTATION_TARGET!>@Ann<!> Foo
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !LANGUAGE: +ProhibitUseSiteTargetAnnotationsOnSuperTypes
|
||||
|
||||
interface Foo
|
||||
|
||||
annotation class Ann
|
||||
|
||||
class E : <!ANNOTATION_ON_SUPERCLASS!>@field:Ann<!> <!ANNOTATION_ON_SUPERCLASS!>@get:Ann<!> <!ANNOTATION_ON_SUPERCLASS!>@set:Ann<!> <!ANNOTATION_ON_SUPERCLASS!>@setparam:Ann<!> Foo
|
||||
|
||||
interface G : <!WRONG_ANNOTATION_TARGET!>@Ann<!> Foo
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +ProhibitUseSiteTargetAnnotationsOnSuperTypes
|
||||
|
||||
interface Foo
|
||||
|
||||
Vendored
+5
-5
@@ -6,22 +6,22 @@
|
||||
annotation class Ann(val x: Int)
|
||||
|
||||
// TESTCASE NUMBER: 1
|
||||
abstract class Foo : @Ann(10) Any()
|
||||
abstract class Foo : <!WRONG_ANNOTATION_TARGET!>@Ann(10)<!> Any()
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
abstract class Bar<T : @Ann(10) Any>
|
||||
abstract class Bar<T : <!WRONG_ANNOTATION_TARGET!>@Ann(10)<!> Any>
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
fun case_3(a: Any) {
|
||||
if (a is @Ann(10) String) return
|
||||
if (a is <!WRONG_ANNOTATION_TARGET!>@Ann(10)<!> String) return
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 4
|
||||
open class TypeToken<T>
|
||||
|
||||
val case_4 = object : TypeToken<@Ann(10) String>() {}
|
||||
val case_4 = object : TypeToken<<!WRONG_ANNOTATION_TARGET!>@Ann(10)<!> String>() {}
|
||||
|
||||
// TESTCASE NUMBER: 5
|
||||
fun case_5(a: Any) {
|
||||
a as @Ann(10) Int
|
||||
a as <!WRONG_ANNOTATION_TARGET!>@Ann(10)<!> Int
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -8,7 +8,7 @@ annotation class Ann(val x: Int)
|
||||
fun foo(i: Inv<@Ann(unresolved_reference) String>) {}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
fun test(vararg a: @Ann(<!UNRESOLVED_REFERENCE!>unresolved_reference<!>) Any) {}
|
||||
fun test(vararg a: @Ann(unresolved_reference) Any) {}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
class A<T>(a: @Ann(<!UNRESOLVED_REFERENCE!>unresolved_reference<!>) T)
|
||||
|
||||
Vendored
+1
-1
@@ -18,4 +18,4 @@ val case_1 = object : TypeToken<@Ann(unresolved_reference) String>() {}
|
||||
*/
|
||||
interface A
|
||||
|
||||
val case_2 = object: @Ann(<!TOO_MANY_ARGUMENTS, TOO_MANY_ARGUMENTS, UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>unresolved_reference<!>) A {}
|
||||
val case_2 = object: @Ann(<!TOO_MANY_ARGUMENTS, UNRESOLVED_REFERENCE!>unresolved_reference<!>) A {}
|
||||
|
||||
Reference in New Issue
Block a user