FIR: report WRONG_ANNOTATION_TARGET(_WITH_USE_SITE_TARGET) on declarations

This commit is contained in:
Mikhail Glukhikh
2021-05-18 11:48:44 +03:00
parent 95f2c52659
commit 2a33a6927c
73 changed files with 394 additions and 392 deletions
@@ -2,6 +2,6 @@
annotation class My
data class Pair(val a: Int, val b: Int)
fun foo(): Int {
val (@My private a, @My public b) = Pair(12, 34)
val (<!WRONG_ANNOTATION_TARGET!>@My<!> private a, <!WRONG_ANNOTATION_TARGET!>@My<!> public b) = Pair(12, 34)
return a + b
}
@@ -5,4 +5,4 @@ annotation class Ann
var x: Int
get() = 1
set(@Ann private x) { }
set(<!WRONG_ANNOTATION_TARGET!>@Ann<!> private x) { }
@@ -8,9 +8,9 @@ annotation class smartset
annotation class base
class My(x: Int) {
@smartget var y = x
<!WRONG_ANNOTATION_TARGET!>@smartget<!> var y = x
@base @smartget @smartset get
@base @smartget @smartset set
@base @smartget @smartset fun foo() = y
@base <!WRONG_ANNOTATION_TARGET!>@smartget<!> <!WRONG_ANNOTATION_TARGET!>@smartset<!> fun foo() = y
}
@@ -2,19 +2,19 @@
@base annotation class derived
@base class correct(@base val x: Int) {
@base constructor(): this(0)
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(<!WRONG_ANNOTATION_TARGET!>@base<!> val x: Int) {
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0)
}
@base enum class My {
@base FIRST,
@base SECOND
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My {
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
}
@base fun foo(@base y: @base Int): Int {
@base fun bar(@base z: @base Int) = z + 1
@base val local = bar(y)
<!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
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
@@ -3,19 +3,19 @@
@base annotation class derived
@base class correct(@base val x: Int, @base w: @base Int) {
@base constructor(): this(0, 0)
@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 @base constructor() {
@base FIRST,
@base SECOND
@base enum class My <!WRONG_ANNOTATION_TARGET!>@base<!> constructor() {
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
}
@base fun foo(@base y: @base Int): Int {
@base fun bar(@base z: @base Int) = z + 1
@base val local = bar(y)
<!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
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
@@ -1,20 +1,20 @@
@Target(AnnotationTarget.CONSTRUCTOR) annotation class base
@base annotation class derived
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
@base class correct(@base val x: Int) {
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(<!WRONG_ANNOTATION_TARGET!>@base<!> val x: Int) {
@base constructor(): this(0)
}
@base enum class My @base constructor() {
@base FIRST,
@base SECOND
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My @base constructor() {
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
}
@base fun foo(@base y: @base Int): Int {
@base fun bar(@base z: @base Int) = z + 1
@base val local = bar(y)
<!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
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
@@ -6,7 +6,7 @@ annotation class special
fun transform(i: Int, tr: (Int) -> Int): Int = <!WRONG_ANNOTATION_TARGET!>@base<!> @special tr(@special i)
@base @special fun foo(i: Int): Int {
@base <!WRONG_ANNOTATION_TARGET!>@special<!> fun foo(i: Int): Int {
val j = <!WRONG_ANNOTATION_TARGET!>@base<!> @special i + 1
if (j == 1) return foo(@special <!WRONG_ANNOTATION_TARGET!>@base<!> 42)
return transform(@special j, @base @special { @special it * 2 })
@@ -2,32 +2,32 @@
@Target(AnnotationTarget.FIELD)
annotation class Field
@Field
<!WRONG_ANNOTATION_TARGET!>@Field<!>
annotation class Another
@Field
val x: Int = 42
@Field
<!WRONG_ANNOTATION_TARGET!>@Field<!>
val y: Int
get() = 13
@Field
abstract class My(@Field arg: Int, @Field val w: Int) {
<!WRONG_ANNOTATION_TARGET!>@Field<!>
abstract class My(<!WRONG_ANNOTATION_TARGET!>@Field<!> arg: Int, @Field val w: Int) {
@Field
val x: Int = arg
@Field
<!WRONG_ANNOTATION_TARGET!>@Field<!>
val y: Int
get() = 0
@Field
<!WRONG_ANNOTATION_TARGET!>@Field<!>
abstract val z: Int
@Field
<!WRONG_ANNOTATION_TARGET!>@Field<!>
fun foo() {}
@Field
<!WRONG_ANNOTATION_TARGET!>@Field<!>
val v: Int by <!UNRESOLVED_REFERENCE!>Delegates<!>.lazy { 42 }
}
@@ -36,10 +36,10 @@ enum class Your {
}
interface His {
@Field
<!WRONG_ANNOTATION_TARGET!>@Field<!>
val x: Int
@Field
<!WRONG_ANNOTATION_TARGET!>@Field<!>
val y: Int
get() = 42
}
@@ -1,23 +0,0 @@
// FILE: annotation.kt
package test
@Target(AnnotationTarget.FILE) annotation class special
annotation class common
// FILE: other.kt
@file:special
package test
@special class Incorrect
// FILE: another.kt
@file:common
package test
@common class Correct
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: annotation.kt
package test
@@ -1,22 +1,22 @@
@Target(AnnotationTarget.FUNCTION) annotation class base
@base annotation class derived
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
@base class correct(@base val x: Int) {
@base constructor(): this(0)
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(<!WRONG_ANNOTATION_TARGET!>@base<!> val x: Int) {
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0)
@base public fun baz() {}
}
@base enum class My @base constructor() {
@base FIRST,
@base SECOND
<!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(@base y: @base Int): Int {
@base fun bar(@base z: @base Int) = z + 1
@base val local = bar(y)
@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
}
@base val z = 0
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
@@ -1,21 +1,21 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
@Target(AnnotationTarget.<!UNRESOLVED_REFERENCE!>INIT<!>) annotation class incorrect
@incorrect annotation class derived
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> annotation class derived
@incorrect class correct(@incorrect val x: Int, @incorrect w: @incorrect Int) {
@incorrect constructor(): this(0, 0)
<!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)
}
@incorrect enum class My @incorrect constructor() {
@incorrect FIRST,
@incorrect SECOND
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> enum class My <!WRONG_ANNOTATION_TARGET!>@incorrect<!> constructor() {
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> FIRST,
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> SECOND
}
@incorrect fun foo(@incorrect y: @incorrect Int): Int {
@incorrect fun bar(@incorrect z: @incorrect Int) = z + 1
@incorrect val local = bar(y)
<!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
}
@incorrect val z = <!WRONG_ANNOTATION_TARGET!>@incorrect<!> 0
<!WRONG_ANNOTATION_TARGET!>@incorrect<!> val z = <!WRONG_ANNOTATION_TARGET!>@incorrect<!> 0
@@ -60,23 +60,23 @@ package test
import test.AnnotationTargets.*
@base @meta @type @konstructor annotation class KMeta
@base @meta @type <!WRONG_ANNOTATION_TARGET!>@konstructor<!> annotation class KMeta
@base @meta @type @method @multiple class KClass(
@base <!WRONG_ANNOTATION_TARGET!>@meta<!> @type <!WRONG_ANNOTATION_TARGET!>@method<!> <!WRONG_ANNOTATION_TARGET!>@multiple<!> class KClass(
@base @fieldann @parameter val y:
@base @type Int) {
@base @multiple @fieldann @local val x = 0
@base @multiple @fieldann <!WRONG_ANNOTATION_TARGET!>@local<!> val x = 0
@method @konstructor @type get
@base @method @multiple @konstructor
fun foo(@parameter @type i:
@base @method @multiple <!WRONG_ANNOTATION_TARGET!>@konstructor<!>
fun foo(@parameter <!WRONG_ANNOTATION_TARGET!>@type<!> i:
@base @multiple Int
): @fieldann @parameter Int {
@local @base @multiple @fieldann val j = i + 1
@local @base <!WRONG_ANNOTATION_TARGET!>@multiple<!> <!WRONG_ANNOTATION_TARGET!>@fieldann<!> val j = i + 1
<!WRONG_ANNOTATION_TARGET!>@base<!> <!WRONG_ANNOTATION_TARGET!>@multiple<!> return j
}
@base @method @konstructor constructor(): this(0)
@base <!WRONG_ANNOTATION_TARGET!>@method<!> @konstructor constructor(): this(0)
}
@@ -1,20 +1,20 @@
@Target(AnnotationTarget.LOCAL_VARIABLE) annotation class base
@base annotation class derived
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
@base class correct(@base val x: Int) {
@base constructor(): this(0)
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(<!WRONG_ANNOTATION_TARGET!>@base<!> val x: Int) {
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0)
}
@base enum class My {
@base FIRST,
@base SECOND
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My {
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
}
@base fun foo(@base y: @base Int): Int {
@base fun bar(@base z: @base Int) = z + 1
<!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
}
@base val z = 0
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0
@@ -1,15 +0,0 @@
@Target(AnnotationTarget.CLASS)
annotation class base
@Target(AnnotationTarget.ANNOTATION_CLASS)
annotation class meta
@base class Outer {
@base @meta class Nested
@base @meta annotation class Annotated
fun foo() {
@base @meta class Local
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
@Target(AnnotationTarget.CLASS)
annotation class base
@@ -1,20 +1,20 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
@Target(AnnotationTarget.PROPERTY) annotation class base
@base annotation class derived
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
@base class correct(@base val x: Int, @base w: Int) {
@base constructor(): this(0, 0)
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(@base val x: Int, <!WRONG_ANNOTATION_TARGET!>@base<!> w: Int) {
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0, 0)
}
@base enum class My {
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My {
@base FIRST,
@base SECOND
}
@base fun foo(@base y: @base Int): Int {
@base fun bar(@base z: @base Int) = z + 1
@base val local = bar(y)
<!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
}
@@ -1,20 +0,0 @@
@Target(AnnotationTarget.TYPE) annotation class base
@base annotation class derived
@base class correct(@base val x: @base Int) {
@base constructor(): this(0)
}
@base enum class My @base constructor() {
@base FIRST,
@base SECOND
}
@base fun foo(@base y: @base Int): Int {
@base fun bar(@base z: @base Int) = z + 1
@base val local = bar(y)
return local
}
@base val z = 0
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
@Target(AnnotationTarget.TYPE) annotation class base
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
@@ -24,10 +24,10 @@ class Class2 {
}
@A fun foo() {}
@A class D
<!WRONG_ANNOTATION_TARGET!>@A<!> fun foo() {}
<!WRONG_ANNOTATION_TARGET!>@A<!> class D
fun foo(i: @A Int) {
@A val i = 1
<!WRONG_ANNOTATION_TARGET!>@A<!> val i = 1
}
fun <T> test(t: @A T): T = t
@@ -35,4 +35,4 @@ fun <T> test(t: @A T): T = t
@Target(AnnotationTarget.TYPE)
internal annotation class C
fun <@C T> test2(t: T): T = t
fun <<!WRONG_ANNOTATION_TARGET!>@C<!> T> test2(t: T): T = t
@@ -1,21 +1,21 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
@Target(AnnotationTarget.VALUE_PARAMETER) annotation class base
@base annotation class derived
<!WRONG_ANNOTATION_TARGET!>@base<!> annotation class derived
@base class correct(@base val x: Int, @base w: Int) {
@base constructor(): this(0, 0)
<!WRONG_ANNOTATION_TARGET!>@base<!> class correct(@base val x: Int, @base w: Int) {
<!WRONG_ANNOTATION_TARGET!>@base<!> constructor(): this(0, 0)
}
@base enum class My {
@base FIRST,
@base SECOND
<!WRONG_ANNOTATION_TARGET!>@base<!> enum class My {
<!WRONG_ANNOTATION_TARGET!>@base<!> FIRST,
<!WRONG_ANNOTATION_TARGET!>@base<!> SECOND
}
@base fun foo(@base y: @base Int): Int {
@base fun bar(@base z: @base Int) = z + 1
@base val local = bar(y)
<!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
}
@base val z = 0
<!WRONG_ANNOTATION_TARGET!>@base<!> val z = 0