[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,6 @@
// !WITH_NEW_INFERENCE
import java.util.ArrayList
@ArrayList<Int>(1, 1) fun b() {}
@Xoo(<!UNRESOLVED_REFERENCE!>x<!>) fun c() {}
@java.lang.Deprecated(<!UNRESOLVED_REFERENCE!>x<!>) fun a() {}
@@ -0,0 +1,2 @@
annotation class ann
class Annotated(@ann val x: Int)
@@ -0,0 +1,15 @@
package a
import java.lang.Deprecated as deprecated
import java.lang.SuppressWarnings as suppresswarnings
@deprecated @suppresswarnings val s: String = "";
@deprecated @suppresswarnings fun main() {
System.out.println("Hello, world!")
}
class Test(@deprecated val s: String,
@suppresswarnings val x : Int) {}
@@ -0,0 +1,8 @@
annotation class My
fun foo() {
val s = object {
@My fun bar() {}
}
s.bar()
}
@@ -0,0 +1,8 @@
annotation class My
fun foo(): Int {
val s = object {
@My val bar: Int = 0
}
return s.bar
}
@@ -0,0 +1,8 @@
@Target(AnnotationTarget.TYPE)
annotation class My
fun foo() {
for (i: @My Int in 0..41) {
if (i == 13) return
}
}
@@ -0,0 +1,5 @@
// Result type can be annotated
@Target(AnnotationTarget.TYPE)
annotation class My(val x: Int)
fun foo(): @My(42) Int = 24
@@ -0,0 +1,9 @@
annotation class My
fun foo(arg: Int): Int {
try {
return 1 / (arg - arg)
} catch (e: @My Exception) {
return -1
}
}
@@ -0,0 +1,5 @@
annotation class Base(val x: Int)
annotation class UseBase(val b: Base = Base(0))
@UseBase class My
@@ -0,0 +1,10 @@
annotation class A1
annotation class A2(val some: Int = 12)
class TopLevelClass<@A1 @A2(3) @A2 @A1(12) @A2("Test") T> {
class InnerClass<@A1 @A2(3) @A2 @A1(12) @A2("Test") T> {
fun test() {
class InFun<@A1 @A2(3) @A2 @A1(12) @A2("Test") T>
}
}
}
@@ -0,0 +1,12 @@
annotation class A1
annotation class A2(val some: Int = 12)
fun <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> topFun() = 12
class SomeClass {
fun <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> method() = 12
fun foo() {
fun <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> innerFun() = 12
}
}
@@ -0,0 +1,3 @@
// Check that there won't be "Rewrite at slice ANNOTATION key" exception - EA-36935
@someErrorAnnotation object Test {
}
@@ -0,0 +1,19 @@
// FILE: a.kt
annotation class annotation
// FILE: test/b.kt
package test
@test.annotation class annotation
// FILE: other/c.kt
package other
annotation class My
@test.annotation class Your
@My class Our
@@ -0,0 +1,6 @@
package test
annotation class A(val a: Int = 12, val b: String = "Test", val c: String)
@A(a = 12, c = "Hello")
object SomeObject
@@ -0,0 +1 @@
annotation @java.lang.Deprecated class my
@@ -0,0 +1,12 @@
annotation class A1
annotation class A2(val some: Int = 12)
val <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> T.topProp: Int get() = 12
class SomeClass {
val <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> T.field: Int get() = 12
fun foo() {
val <@A1 @A2(3) @A2 @A1(12) @A2("Test") T> localVal = 12
}
}
@@ -0,0 +1,10 @@
annotation class my
annotation class my1(val i : Int)
annotation class my2(val i : Int = 0)
@my fun foo() {}
@my1 fun foo2() {}
@my1(2) fun foo3() {}
@my2() fun foo4() {}
@my2 fun foo41() {}
@my2(2) fun foo42() {}
@@ -0,0 +1,35 @@
annotation class Ann
annotation class Ann1(val a: Int)
annotation class Ann2(val a: Ann1)
annotation class Ann3(val a: Ann1 = Ann1(1))
annotation class Ann4(val value: String)
@Ann2(Ann1(1)) val a = 1
@Ann2(a = Ann1(1)) val c = 2
@Ann4("a") class MyClass
fun foo() {
Ann()
val a = Ann()
<!INAPPLICABLE_CANDIDATE!>Ann1<!>()
Ann1(1)
bar(Ann())
bar(a = Ann())
val ann = javaClass<MyClass>().getAnnotation(javaClass<Ann4>())
ann!!.value()
}
fun bar(a: Ann = Ann()) {
if (a is Ann) {}
}
operator fun String.invoke() {}
// from stdlib
fun <T> javaClass() : Class<T> = null as Class<T>
@@ -0,0 +1,22 @@
annotation class Ann
annotation class Ann2
class C {
fun foo() {
class Local {
@Ann0
@Ann @Ann3
@Ann2(1)
@Ann4<!SYNTAX!><!>
}
}
@Ann0
@Ann @Ann3
@Ann2(1)
@Ann4<!SYNTAX!><!>
}
@Ann0
@Ann @Ann3
@Ann2(1)
@Ann4<!SYNTAX!><!>
@@ -0,0 +1,13 @@
annotation class Ann
class C {
fun foo() {
class Local {
@Ann<!SYNTAX!><!>
}
}
@Ann<!SYNTAX!><!>
}
@Ann<!SYNTAX!><!>
@@ -0,0 +1,16 @@
annotation class Ann
class C {
fun test() {
@Ann<!SYNTAX!><!>
}
fun foo() {
class Local {
@Ann<!SYNTAX!><!>
}
}
@Ann<!SYNTAX!><!>
}
@Ann<!SYNTAX!><!>
@@ -0,0 +1,5 @@
import java.lang.Deprecated as deprecated
@java.lang.Deprecated fun foo() {}
@deprecated fun foo1() {}
@@ -0,0 +1,10 @@
import java.lang.annotation.Retention
import java.lang.annotation.Target
import java.lang.annotation.*
@java.lang.annotation.Retention(RetentionPolicy.CLASS)
annotation class my
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR)
annotation class my1
@@ -0,0 +1,9 @@
annotation class Ann
data class Pair(val x: Int, val y: Int)
fun foo(): Int {
@Ann val (a, b) = Pair(12, 34)
@Err val (c, d) = Pair(56, 78)
return a + b + c + d
}
@@ -0,0 +1,4 @@
// Functions can be recursively annotated
annotation class ann(val x: Int)
@ann(bar()) fun foo() = 1
@ann(foo()) fun bar() = 2
@@ -0,0 +1,3 @@
class Foo
@Foo class Bar
@@ -0,0 +1,3 @@
// Class CAN be recursively annotated
@RecursivelyAnnotated(1)
annotation class RecursivelyAnnotated(val x: Int)
@@ -0,0 +1,3 @@
// Function parameter CAN be recursively annotated
annotation class ann(val x: Int)
fun foo(@ann(foo(1)) x: Int): Int = x
@@ -0,0 +1,3 @@
// Functions can be recursively annotated
annotation class ann(val x: Int)
@ann(foo()) fun foo() = 1
@@ -0,0 +1,3 @@
// Properties can be recursively annotated
annotation class ann(val x: Int)
@ann(x) const val x: Int = 1
@@ -0,0 +1,2 @@
// Class constructor parameter CAN be recursively annotated
annotation class RecursivelyAnnotated(@RecursivelyAnnotated(1) val x: Int)
@@ -0,0 +1,3 @@
// Class constructor parameter type CAN be recursively annotated
@Target(AnnotationTarget.TYPE)
annotation class RecursivelyAnnotated(val x: @RecursivelyAnnotated(1) Int)
@@ -0,0 +1,2 @@
// Class constructor parameter CAN be recursively annotated
annotation class RecursivelyAnnotated(@RecursivelyAnnotated(1) val x: Int)
@@ -0,0 +1,5 @@
// Properties can be recursively annotated
annotation class ann(val x: Int)
class My {
@ann(x) val x: Int = 1
}
@@ -0,0 +1,2 @@
// Class constructor parameter CAN be recursively annotated
class RecursivelyAnnotated(@RecursivelyAnnotated(1) val x: Int)
@@ -0,0 +1,13 @@
// !LANGUAGE: +RestrictRetentionForExpressionAnnotations
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class TestRetentionSource
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.BINARY)
annotation class TestRetentionBinary
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.RUNTIME)
annotation class TestRetentionRuntime
@@ -0,0 +1,13 @@
// !LANGUAGE: -RestrictRetentionForExpressionAnnotations
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class TestRetentionSource
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.BINARY)
annotation class TestRetentionBinary
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.RUNTIME)
annotation class TestRetentionRuntime
@@ -0,0 +1,9 @@
package test
// Checks that there is no rewrite error at ANNOTATION slice because of resolving annotations for object in lazy resolve and resolving
// object as property (method tries to resolve annotations too).
@BadAnnotation
object SomeObject
val some = SomeObject
@@ -0,0 +1,8 @@
package test
@BadAnnotation(1)
object SomeObject
val some = SomeObject
annotation class BadAnnotation(val s: String)
@@ -0,0 +1,11 @@
// SKIP_ERRORS_BEFORE
annotation class X(val value: Y, val y: Y)
annotation class Y()
@X(@Y()<!SYNTAX!><!>, y = Y())
fun foo1() {
}
@X(@Y()<!SYNTAX!><!>, y = @Y()<!SYNTAX!><!>)
fun foo2() {
}
@@ -0,0 +1,8 @@
val a = object: T {}
open class C
interface T
annotation class Ann: C()
annotation class Ann2: T
annotation class Ann3: T by a
annotation class Ann4: C(), T
@@ -0,0 +1,15 @@
annotation class B
class A {
annotation companion object {}
}
annotation object O {}
annotation interface T {}
annotation fun f() = 0
annotation val x = 0
annotation var y = 0
@@ -0,0 +1,29 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
annotation class Ann
fun f(@Ann x: Int) {}
val inVal: (@Ann x: Int)->Unit = {}
fun inParam(fn: (@Ann x: Int)->Unit) {}
fun inParamNested(fn1: (fn2: (@Ann n: Int)->Unit)->Unit) {}
fun inReturn(): (@Ann x: Int)->Unit = {}
class A : (@Ann Int)->Unit {
override fun invoke(p1: Int) {
var lambda: (@Ann x: Int)->Unit = {}
}
val prop: (@Ann x: Int)->Unit
get(): (@Ann x: Int)->Unit = {}
}
@Target(AnnotationTarget.TYPE)
annotation class TypeAnn
val onType: (@TypeAnn A).(@Ann a: @TypeAnn A, @TypeAnn A)->@TypeAnn A? = { null }
fun (@TypeAnn A).extFun(@Ann a: @TypeAnn A): @TypeAnn A? = null
@@ -0,0 +1,12 @@
const val iConst = 42
val iVal = 42
fun iFun() = 42
annotation class Ann(val x: Int)
annotation class Test1(val x: Int = 42)
annotation class Test2(val x: Int = iConst)
annotation class Test3(val x: Int = 1 + iConst + 1)
annotation class Test4(val x: Int = iVal)
annotation class Test5(val x: Int = 1 + iVal + 1)
annotation class Test6(val x: Int = iFun())
annotation class Test7(val x: Int = 1 + iFun() + 1)
@@ -0,0 +1,6 @@
annotation class Ann(vararg val i: Boolean)
fun foo() {
val bool1 = true
@Ann(bool1) val a = bool1
}
@@ -0,0 +1,16 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
annotation class Ann(vararg val i: Boolean)
fun foo() {
val a1 = 1 > 2
val a2 = 1 == 2
val a3 = a1 == a2
val a4 = a1 > a2
@Ann(
a1,
a2,
a3,
a1 > a2,
a1 == a2
) val b = 1
}
@@ -0,0 +1,15 @@
// !LANGUAGE: +ProhibitNonConstValuesAsVarargsInAnnotations
annotation class AnnE(val i: MyEnum)
@AnnE(e)
class Test
val e: MyEnum = MyEnum.A
enum class MyEnum {
A
}
@AnnE(Test())
class Test2
@@ -0,0 +1,15 @@
// !LANGUAGE: -ProhibitNonConstValuesAsVarargsInAnnotations
annotation class AnnE(val i: MyEnum)
@AnnE(e)
class Test
val e: MyEnum = MyEnum.A
enum class MyEnum {
A
}
@AnnE(Test())
class Test2
@@ -0,0 +1,25 @@
// FILE: Test.java
public class Test {
public static int i1 = 1;
public static final int i2 = 1;
public static final int i3 = i1;
public static final int i4 = i2;
public static int i5 = i1;
public static int i6 = i2;
public final int i7 = 1;
}
// FILE: a.kt
annotation class Ann(vararg val i: Int)
@Ann(
Test.i1,
Test.i2,
Test.i3,
Test.i4,
Test.i5,
Test.i6,
Test().i7
)
class A
@@ -0,0 +1,18 @@
annotation class Ann(vararg val i: Int)
@Ann(
i1,
i2,
i3,
i4,
i5,
i6
)
class Test
var i1 = 1 // var
const val i2 = 1 // val
val i3 = i1 // val with var in initializer
const val i4 = i2 // val with val in initializer
var i5 = i1 // var with var in initializer
var i6 = i2 // var with val in initializer
@@ -0,0 +1,18 @@
annotation class AnnE(val i: String)
enum class MyEnum {
A
}
@AnnE("1" + MyEnum.A)
class Test
@AnnE("1" + MyEnum::class)
class Test2
@AnnE("1" + AnnE("23"))
class Test3
@AnnE("1" + arrayOf("23", "34"))
class Test4
@@ -0,0 +1,28 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
annotation class Ann(vararg val i: String)
const val topLevel = "topLevel"
fun foo() {
val a1 = "a"
val a2 = "b"
val a3 = a1 + a2
val a4 = 1
val a5 = 1.0
@Ann(
a1,
a2,
a3,
"$topLevel",
"$a1",
"$a1 $topLevel",
"$a4",
"$a5",
a1 + a2,
"a" + a2,
"a" + topLevel,
"a" + a4
) val b = 1
}
@@ -0,0 +1,26 @@
// !RENDER_DIAGNOSTICS_MESSAGES
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER
// !WITH_NEW_INFERENCE
fun f1(x: String) {}
fun f2(f: () -> Unit) {}
fun test1() = <!INAPPLICABLE_CANDIDATE!>f2<!>(::f1)
@Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPE)
annotation class Ann
fun <@Ann R : @Ann Any> f3(a: Array<@Ann R>): Array<@Ann R?> = null!!
fun test2(a: @Ann Array<in @Ann Int>) {
val r: Array<in Int?> = <!INAPPLICABLE_CANDIDATE!>f3<!>(a)
}
var test3: Int = 0
set(s: @Ann String) {}
fun f4(fn: (@Ann Int, @Ann Int) -> Unit) {}
val test4 = <!INAPPLICABLE_CANDIDATE!>f4<!> { single -> }
@@ -0,0 +1,19 @@
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class Ann(val x: Int = 1)
inline fun bar(block: () -> Int): Int = block()
fun foo() {
bar() @Ann(1) @Ann(2) { 101 }
bar() @Ann(3) { 102 }
bar @Ann l1@ {
return@l1 103
}
bar @Ann("") {
104
}
}
@@ -0,0 +1,44 @@
//!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
@@ -0,0 +1,19 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS,
AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION,
AnnotationTarget.EXPRESSION, AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class Ann(val x: Int = 6)
@Ann(1) @Ann(2) @Ann(3) private class A @Ann constructor() {
@Ann(x = 5) fun foo() {
1 + @Ann(1) 1 * @Ann("") 6
@Ann fun local() {}
}
@Ann val x = 1
fun bar(x: @Ann(1) @Ann(2) @Ann(3) Int) {}
}
@@ -0,0 +1,62 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class Ann1
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class Ann2(val x: String)
fun bar() {}
fun bar(block: () -> Unit) {}
fun foo(y: IntArray) {
@Ann1 bar()
@Ann1 bar() { }
@Ann1 bar { }
@Ann2("") bar()
@Ann2("") bar() { }
@Ann2("") bar { }
@Ann1 @Ann2("") bar()
var x = 1
@Ann1 ++x
@Ann1 x++
@Ann2("") ++x
@Ann2("") x++
@Ann1 @Ann2("") ++x
@Ann1 @Ann2("") x++
@Ann1 y[0]
@Ann1 { x: Int -> x }
@Ann1 <!UNRESOLVED_REFERENCE!>{ x: Int -> x }(1)<!>
@Ann1 object { fun foo() = 1 }
@Ann1 object { fun foo() = 1 }.foo()
@Ann1() (x * x)
var z = 1
@Ann1 x + z
@Ann1 x = x + 2
@Ann1 x += z + 2
@Ann1 x + 6 * 2 > 0
@Ann1 x * 6 + 2 > 0
@Ann1 object { operator fun plus(x: Int) = 1 } + 1
@Ann1 object { operator fun plus(x: Int) = 1 } + 1 * 4 > 0
@Ann1 x foo z + 8
1 + @Ann1 x
1 + @Ann1 x * z + 8
x foo @Ann1 z + 8
}
infix fun Int.foo(other: Int) = 1
@@ -0,0 +1,11 @@
// FULL_JDK
import java.lang.annotation.Repeatable
@java.lang.annotation.Repeatable(Annotations::class) annotation class RepAnn
@Repeatable(OtherAnnotations::class) annotation class OtherAnn
annotation class Annotations(vararg val value: RepAnn)
annotation class OtherAnnotations(vararg val value: OtherAnn)
@@ -0,0 +1,11 @@
// This test checks that annotations on extension function types are preserved. See the corresponding .txt file
@Target(AnnotationTarget.TYPE)
annotation class ann
interface Some {
fun f1(): String.() -> Int
fun f2(): @ExtensionFunctionType() (String.() -> Int)
fun f3(): @ann String.() -> Int
fun f4(): @ExtensionFunctionType @ann() (String.() -> Int)
}
@@ -0,0 +1,14 @@
annotation class Ann(val x: Int)
data class A(val x: Int, val y: Int)
fun bar(): Array<A> = null!!
fun foo() {
for (@Ann(1) i in 1..100) {}
for (@Ann(2) i in 1..100) {}
for (@Ann(3) (x, @Ann(4) y) in bar()) {}
for (@Err() (x,y) in bar()) {}
}
@@ -0,0 +1,70 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -CAST_NEVER_SUCCEEDS -CANNOT_CHECK_FOR_ERASED -UNCHECKED_CAST -UNUSED_ANONYMOUS_PARAMETER
// SKIP_TXT
// Issue: KT-31734
@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class Foo
fun foo1(x: @Foo () -> Unit) = x as Iterable<@Foo () -> Unit>?
fun foo2() = null as @Foo () -> Unit
fun foo3(x: Any?) {
if (x is (@Foo () -> Unit)?) {
}
}
fun foo4(x: Any) = x is @Foo () -> (() -> Unit?)
fun foo5(x: Any): @Foo () -> Unit = x as @Foo() @[Foo Foo()] @Foo () -> Unit
fun foo6() {
val x: @Foo() @[Foo Foo()] @Foo () -> Unit = {}
}
fun foo7() {
val x: @Foo (@Foo () -> Unit) -> Unit = { x: @Foo () -> Unit -> }
}
fun foo8(x: Any?) {
val x: (@Foo () -> Unit)? = {}
}
fun foo9(x: (@Foo () -> Unit)?) = x as Iterable<(@Foo () -> Unit?)?>?
fun foo10(x: @[Foo] () -> Unit) = x as Iterable<@Foo() () -> Unit>?
fun foo11(x: @[Foo ] () -> Unit) = x as Iterable<@Foo() () -> Unit>?
fun foo12(x: @[Foo/**/] () -> Unit) = x as Iterable<@Foo() () -> Unit>?
val foo13: @Foo (x: @Foo Any) -> Unit get() = {}
val foo14: @Foo (x: @Foo () -> Unit) -> Unit get() = {}
val foo15: @Foo () @Foo () -> Unit get() = {}
val foo16: @Foo @Foo () @Foo () -> Unit get() = {}
val foo17: @Foo() @Foo () @Foo () -> Unit get() = {}
val foo18: @Foo()@Foo () @Foo () -> Unit get() = {}
val foo19: @Foo@Foo () @Foo () -> Unit get() = {}
val foo20: @Foo@Foo () -> Unit get() = {}
val foo21: @Foo()@Foo () -> Unit get() = {}
val foo22: @Foo (x: @Foo () -> Unit) -> Unit get() = {}
val foo23: @Foo (@Foo () -> Unit) -> Unit get() = {}
val foo24: @Foo (@Foo () -> Unit, @Foo () -> Unit) -> Unit get() = {x, y -> }
val foo25: @Foo (x: @Foo Any, @Foo Any) -> Unit get() = {x, y -> }
val foo26: @Foo suspend () -> Unit = {}
@@ -0,0 +1,67 @@
// !LANGUAGE: +NonParenthesizedAnnotationsOnFunctionalTypes
// !DIAGNOSTICS: -UNUSED_VARIABLE -CAST_NEVER_SUCCEEDS -CANNOT_CHECK_FOR_ERASED -UNCHECKED_CAST -UNUSED_ANONYMOUS_PARAMETER
// SKIP_TXT
// Issue: KT-31734
@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class Foo
class MyClass
fun foo1(x: @Foo () -> Unit) = x as Iterable<@Foo () -> Unit>?
fun foo2() = null as @Foo () -> Unit
fun foo3(x: Any?) {
if (x is (@Foo () -> Unit)?) {
}
}
fun foo4(x: Any) = x is @Foo () -> (() -> Unit?)
fun foo5(x: Any): @Foo () -> Unit = x as @Foo() @[Foo Foo()] @Foo () -> Unit
fun foo6() {
val x: @Foo() @[Foo Foo()] @Foo () -> Unit = {}
}
fun foo7() {
val x: @Foo (@Foo () -> Unit) -> Unit = { x: @Foo () -> Unit -> }
}
fun foo10(x: @[Foo()] () -> Unit) = x as Iterable<@Foo() () -> Unit>?
fun foo11(x: @[Foo] () -> Unit) = x as Iterable<@Foo() () -> Unit>?
fun foo12(x: @[Foo ] () -> Unit) = x as Iterable<@Foo() () -> Unit>?
fun foo13(x: @[Foo/**/] () -> Unit) = x as Iterable<@Foo() () -> Unit>?
val foo14: @Foo (x: @Foo () -> Unit) -> Unit get() = {}
val foo15: @Foo () @Foo () -> Unit get() = {}
val foo16: @Foo @Foo () @Foo () -> Unit get() = {}
val foo17: @Foo() @Foo () @Foo () -> Unit get() = {}
val foo18: @Foo()@Foo () @Foo () -> Unit get() = {}
val foo19: @Foo@Foo () @Foo () -> Unit get() = {}
val foo20: @Foo@Foo () -> Unit get() = {}
val foo21: @Foo()@Foo () -> Unit get() = {}
val foo22: @Foo (x: @Foo () -> Unit) -> Unit get() = {}
val foo23: @Foo (@Foo () -> Unit) -> Unit get() = {}
val foo24: @Foo (@Foo () -> Unit, @Foo () -> Unit) -> Unit get() = {x, y -> }
val foo25: @Foo (x: @Foo Any, @Foo Any) -> Unit get() = {x, y -> }
val foo26: @Foo suspend () -> Unit = {}
@@ -0,0 +1,46 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -CAST_NEVER_SUCCEEDS -CANNOT_CHECK_FOR_ERASED -UNCHECKED_CAST -UNUSED_ANONYMOUS_PARAMETER
// SKIP_TXT
// Issue: KT-31734
@Target(AnnotationTarget.TYPE, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class Foo
fun foo1(x: @Foo() () -> Unit) = x as Iterable<@Foo() () -> Unit>?
fun foo2() = null as @Foo() () -> Unit
fun foo3(x: Any?) {
if (x is (@Foo() () -> Unit)?) {
}
}
fun foo4(x: Any) = x is @Foo() () -> (() -> Unit?)
fun foo5(x: Any): @Foo() () -> Unit = x as @Foo () @[Foo Foo ()] @Foo() () -> Unit
fun foo6() {
val x: @Foo() @[Foo Foo()] @Foo() () -> Unit = {}
}
fun foo7() {
val x: @Foo() (@Foo() () -> Unit) -> Unit = { x: @Foo() () -> Unit -> }
}
fun foo8(x: @[Foo() ] () -> Unit) = x as Iterable<@Foo() () -> Unit>?
fun foo9(x: @[Foo()] () -> Unit) = x as Iterable<@Foo() () -> Unit>?
fun foo10() {
val x: @Foo () @Foo () () -> Unit = {}
}
fun foo11() {
val x: @Foo @Foo () () -> Unit = {}
}
fun foo12() {
val x: @Foo() @Foo () () -> Unit = {}
}
@@ -0,0 +1,38 @@
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package test
import kotlin.internal.RequireKotlin
@RequireKotlin("")
fun f01() {}
@RequireKotlin("x")
fun f02() {}
@RequireKotlin("1")
fun f03() {}
@RequireKotlin("1.0-beta")
fun f04() {}
@RequireKotlin("1.1.0-dev-1111")
fun f05() {}
@RequireKotlin("1.5.3.7")
fun f06() {}
@RequireKotlin("1..0")
fun f07() {}
@RequireKotlin(" 1.0")
fun f08() {}
@RequireKotlin("1.1")
fun ok1() {}
@RequireKotlin("1.1.0")
fun ok2() {}
@RequireKotlin("0.0.0")
fun ok3() {}
@@ -0,0 +1,74 @@
@SinceKotlin("")
fun f01() {}
@SinceKotlin("x")
fun f02() {}
@SinceKotlin("1")
fun f03() {}
@SinceKotlin("1,0")
fun f04() {}
@SinceKotlin("1,0,1")
fun f05() {}
@SinceKotlin("a.b")
fun f06() {}
@SinceKotlin("1.a")
fun f07() {}
@SinceKotlin("1.0.a")
fun f08() {}
@SinceKotlin("1.0-beta")
fun f09() {}
@SinceKotlin("1.1.0-dev-1111")
fun f10() {}
@SinceKotlin("1.1.0+rc")
fun f11() {}
@SinceKotlin("1.5.3.7")
fun f12() {}
@SinceKotlin("01.1")
fun f13() {}
@SinceKotlin("1.01")
fun f14() {}
@SinceKotlin("-1.0")
fun f15() {}
@SinceKotlin("1.-1.0")
fun f16() {}
@SinceKotlin("0.00.1")
fun f17() {}
@SinceKotlin("1..0")
fun f18() {}
@SinceKotlin(" 1.0")
fun f19() {}
@SinceKotlin("1.0 ")
fun f20() {}
@SinceKotlin("1.1")
fun ok1() {}
@SinceKotlin("1.1.0")
fun ok2() {}
@SinceKotlin("0.0.0")
fun ok3() {}
@SinceKotlin("123456789012345678901234567890.123456789012345678901234567890.123456789012345678901234567890")
fun ok4() {}
@@ -0,0 +1,4 @@
// !DIAGNOSTICS: -FINAL_SUPERTYPE
// This error needs to be suppressed to cause light class generation
class Foo : Target()
@@ -0,0 +1,25 @@
// !DIAGNOSTICS: -SUPERTYPES_FOR_ANNOTATION_CLASS -VIRTUAL_MEMBER_HIDDEN -FINAL_SUPERTYPE -MISSING_DEPENDENCY_SUPERCLASS
// These errors need to be suppressed to cause light class generation
// FILE: test.kt
annotation class Ann : Target()
annotation class Ann2(vararg val allowedTargets: AnnotationTarget) : Target()
interface I : J {
override fun foo(): List<String> = throw Exception()
}
class C : I {
fun bar(): Set<Number> = throw Exception()
}
annotation class Ann3 : C()
annotation class Ann4 : I
// FILE: J.java
import java.util.Collection;
import kotlin.annotation.Target;
public interface J extends Target {
Collection<String> foo();
}
@@ -0,0 +1,76 @@
package test
import java.lang.annotation.RetentionPolicy
// CORRECT
annotation class Ann1(val p1: Int,
val p2: Byte,
val p3: Short,
val p4: Long,
val p5: Double,
val p6: Float,
val p7: Char,
val p8: Boolean)
annotation class Ann2(val p1: String)
annotation class Ann3(val p1: Ann1)
annotation class Ann4(val p1: IntArray,
val p2: ByteArray,
val p3: ShortArray,
val p4: LongArray,
val p5: DoubleArray,
val p6: FloatArray,
val p7: CharArray,
val p8: BooleanArray)
annotation class Ann5(val p1: MyEnum)
annotation class Ann6(val p: Class<*>)
annotation class Ann7(val p: RetentionPolicy)
annotation class Ann8(val p1: Array<String>,
val p2: Array<Class<*>>,
val p3: Array<MyEnum>,
val p4: Array<Ann1>)
annotation class Ann9(
val error: Unresolved = <!UNRESOLVED_REFERENCE!>Unresolved<!>.<!UNRESOLVED_REFERENCE!>VALUE<!>
)
// INCORRECT
annotation class InAnn1(val p1: Int?,
val p3: Short?,
val p4: Long?,
val p5: Double?,
val p6: Float?,
val p7: Char?,
val p8: Boolean?)
annotation class InAnn4(val p1: Array<Int>,
val p2: Array<Int>?)
annotation class InAnn6(val p: Class<*>?)
annotation class InAnn7(val p: RetentionPolicy?)
annotation class InAnn8(val p1: Array<Int>,
val p2: Array<Int?>,
val p3: Array<MyClass>,
val p4: Array<IntArray>)
annotation class InAnn9(val p: MyClass)
annotation class InAnn10(val p1: String?)
annotation class InAnn11(val p1: Ann1?)
annotation class InAnn12(val p1: MyEnum?)
annotation class InAnn13(vararg val p1: String,
vararg val p2: Class<*>,
vararg val p3: MyEnum,
vararg val p4: Ann1,
vararg val p5: Int)
enum class MyEnum {
A
}
class MyClass
@@ -0,0 +1,19 @@
// FULL_JDK
// FILE: RepeatableAnnotation.java
import java.lang.annotation.Repeatable;
@Repeatable(RepeatableAnnotations.class)
public @interface RepeatableAnnotation {
}
// FILE: RepeatableAnnotations.java
public @interface RepeatableAnnotations {
RepeatableAnnotation[] value();
}
// FILE: RepeatableUse.kt
// Error should be gone when Java 8 Target will be available
@RepeatableAnnotation @RepeatableAnnotation class My
@@ -0,0 +1,20 @@
// FULL_JDK
// FILE: RepeatableAnnotation.java
import java.lang.annotation.*;
@Repeatable(RepeatableAnnotations.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface RepeatableAnnotation {
}
// FILE: RepeatableAnnotations.java
public @interface RepeatableAnnotations {
RepeatableAnnotation[] value();
}
// FILE: RepeatableUse.kt
// Error should be gone when Java 8 Target will be available
@RepeatableAnnotation @RepeatableAnnotation class My
@@ -0,0 +1,9 @@
// FILE: UnrepeatableAnnotation.java
public @interface UnrepeatableAnnotation {
}
// FILE: UnrepeatableUse.kt
@UnrepeatableAnnotation @UnrepeatableAnnotation class My
@@ -0,0 +1,10 @@
// !WITH_NEW_INFERENCE
fun foo(@varargs f : Int) {}
var bar : Int = 1
set(@varargs v) {}
val x : (Int) -> Int = {@varargs x <!SYNTAX!>: Int -> x<!>}
class Hello(@varargs args: Any) {
}
@@ -0,0 +1,14 @@
// !WITH_NEW_INFERENCE
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class test
fun foo(@test f : Int) {}
var bar : Int = 1
set(@test v) {}
val x : (Int) -> Int = {@test x <!SYNTAX!>: Int -> x<!>} // todo fix parser annotation on lambda parameter
class Hello(@test args: Any) {
}
@@ -0,0 +1,31 @@
// !LANGUAGE: +NestedClassesInAnnotations
annotation class Annotation2() {
public val s: String = ""
}
annotation class Annotation3() {
public fun foo() {}
}
annotation class Annotation4() {
class Foo() {}
}
annotation class Annotation5() {
companion object {}
}
annotation class Annotation6() {
init {}
}
annotation class Annotation1() {}
annotation class Annotation7(val name: String) {}
annotation class Annotation8(var name: String = "") {}
annotation class Annotation9(val name: String)
annotation class Annotation10
@@ -0,0 +1,31 @@
// !LANGUAGE: -NestedClassesInAnnotations
annotation class Annotation2() {
public val s: String = ""
}
annotation class Annotation3() {
public fun foo() {}
}
annotation class Annotation4() {
class Foo() {}
}
annotation class Annotation5() {
companion object {}
}
annotation class Annotation6() {
init {}
}
annotation class Annotation1() {}
annotation class Annotation7(val name: String) {}
annotation class Annotation8(var name: String = "") {}
annotation class Annotation9(val name: String)
annotation class Annotation10
@@ -0,0 +1,5 @@
annotation class Ann(
val a: Int,
var b: Int,
c: String
)
@@ -0,0 +1,23 @@
// !LANGUAGE: +NestedClassesInAnnotations
annotation class Foo {
class Nested
inner class Inner
enum class E { A, B }
object O
interface I
annotation class Anno(val e: E)
companion object {
val x = 1
const val y = ""
}
constructor(s: Int) {}
init {}
fun function() {}
val property get() = Unit
}
@@ -0,0 +1 @@
annotation class Ann(val x: Int, val<!SYNTAX!><!> )
@@ -0,0 +1,5 @@
fun foo() = @ann 1
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class ann
@@ -0,0 +1,7 @@
annotation class ann
fun test(@ann p: Int) {
}
val bar = fun(@ann g: Int) {}
@@ -0,0 +1,11 @@
class A {
@ann init {}
@aaa init {}
}
interface T {
@ann init {}
@aaa init {}
}
annotation class ann
@@ -0,0 +1,12 @@
fun test() {
@ann
while (2 < 1) {}
@ann
do {} while (2 < 1)
@ann
for (i in 1..2) {}
}
annotation class ann
@@ -0,0 +1,12 @@
fun test() {
@ann
while (2 > 1) {}
@ann
do {} while (2 > 1)
@ann
for (i in 1..2) {}
}
annotation class ann
@@ -0,0 +1,7 @@
fun test(): Any? {
@ann val (a, b) = P(1, 1)
return a + b
}
annotation class ann
data class P(val a: Int, val b: Int)
@@ -0,0 +1,14 @@
class Annotation(val x: Int) {
fun baz() {}
fun bar() = x
}
fun foo(annotation: Annotation): Int {
if (annotation.bar() == 0) {
annotation.baz()
return 0
}
else {
return -1
}
}
@@ -0,0 +1,10 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
class Annotation {
fun setProblemGroup() {}
fun getQuickFixes() = 0
}
fun registerQuickFix(annotation: Annotation) {
annotation.setProblemGroup()
val fixes = annotation.getQuickFixes()
}
@@ -0,0 +1,10 @@
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class ExprAnn
fun foo(): Int {
var a: Int
@ExprAnn a = 1
@ExprAnn a += 1
return a
}
@@ -0,0 +1,8 @@
@MustBeDocumented
annotation class DocAnn
annotation class NotDocAnn
@DocAnn class My
@NotDocAnn class Your
@@ -0,0 +1,10 @@
// See KT-9145
@Target(AnnotationTarget.CLASS)
annotation class Ann
fun foo() {
for (@Ann private x in 1..100) {
if (x == 1) return
}
}
@@ -0,0 +1,12 @@
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class ExprAnn
@Target(AnnotationTarget.FUNCTION)
annotation class FunAnn
fun foo(): Int {
val x = @ExprAnn fun() = 1
val y = @FunAnn fun() = 2
return x() + y()
}
@@ -0,0 +1,40 @@
// !WITH_NEW_INFERENCE
@Target(AnnotationTarget.FUNCTION)
annotation class FunAnn
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.SOURCE)
annotation class SourceAnn
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class ExprAnn
fun bar(arg: () -> Int) = arg()
inline fun fast(arg: () -> Int) = arg()
inline fun fast2(x: Int, arg: () -> Int) = x + arg()
@FunAnn fun gav() = 13
fun foo(arg: Int) {
// Literal is annotatable
bar @FunAnn { arg }
// Annotatable in principle but useless, fast is inline
fast @FunAnn { arg }
fast2(1, @FunAnn { arg })
// Source annotation, ok
fast @SourceAnn { arg }
fast2(1, @SourceAnn { arg })
// Expression annotation, ok
fast @ExprAnn { arg }
fast2(1, @ExprAnn { arg })
// Function expression too
val f = @FunAnn fun(): Int { return 42 }
// But here, f and gav should be annotated instead
bar(@FunAnn f)
bar(@FunAnn ::gav)
// Function expression, ok
fast(f)
}
@@ -0,0 +1,20 @@
// FILE: DocumentedAnnotations.java
import java.lang.annotation.*;
public class DocumentedAnnotations {
@Documented public @interface DocAnn {};
public @interface NotDocAnn {};
@Documented @Retention(RetentionPolicy.RUNTIME) public @interface RunDocAnn {};
}
// FILE: DocumentedAnnotations.kt
@DocumentedAnnotations.DocAnn class My
@DocumentedAnnotations.NotDocAnn class Your
@DocumentedAnnotations.RunDocAnn class His
@@ -0,0 +1,9 @@
import java.lang.annotation.*
@java.lang.annotation.Target(ElementType.PACKAGE)
@Target(AnnotationTarget.CLASS)
annotation class my
@java.lang.annotation.Retention(RetentionPolicy.SOURCE)
@Retention(AnnotationRetention.BINARY)
annotation class your
@@ -0,0 +1,35 @@
// FILE: AnnotationRetentions.java
import java.lang.annotation.*;
public class AnnotationRetentions {
public @interface BaseAnnotation {
}
@Retention(RetentionPolicy.SOURCE)
public @interface SourceAnnotation {
}
@Retention(RetentionPolicy.CLASS)
public @interface BinaryAnnotation {
}
@Retention(RetentionPolicy.RUNTIME)
public @interface RuntimeAnnotation {
}
}
// FILE: AnnotationRetentions.kt
@AnnotationRetentions.BaseAnnotation class BaseClass
@AnnotationRetentions.SourceAnnotation class SourceClass
@AnnotationRetentions.BinaryAnnotation class BinaryClass
@AnnotationRetentions.RuntimeAnnotation class RuntimeClass
@@ -0,0 +1,7 @@
@Target(AnnotationTarget.CLASS)
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)
return a + b
}
@@ -0,0 +1,8 @@
@Target(AnnotationTarget.CLASS)
annotation class Ann
open class My
fun foo(): My {
return (@Ann object: My() {})
}
@@ -0,0 +1,13 @@
@Target(AnnotationTarget.FUNCTION)
annotation class FunAnn
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class ExprAnn
fun foo(): Int {
var x = 5
@FunAnn ++x
@ExprAnn ++x
return x
}
@@ -0,0 +1,31 @@
@Repeatable
annotation class repann
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class repann1(val x: Int)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class repann2(val f: Boolean)
@Retention(AnnotationRetention.BINARY)
@Repeatable
annotation class binrepann
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
@Repeatable
annotation class repexpr
@repann @repann class DoubleAnnotated
@repann1(1) @repann1(2) @repann1(3) class TripleAnnotated
@repann2(true) @repann2(false) @repann2(false) @repann2(true) class FourTimesAnnotated
@binrepann @binrepann class BinaryAnnotated
@repann @repann fun foo(@repann @repann x: Int): Int {
@repexpr @repexpr return x
}
@@ -0,0 +1,4 @@
@Retention(AnnotationRetention.SOURCE)
annotation class sourceann
@sourceann class AnnotatedAtSource
@@ -0,0 +1,8 @@
// KT-9145
@Target(AnnotationTarget.CLASS)
annotation class Ann
var x: Int
get() = 1
set(@Ann private x) { }

Some files were not shown because too many files have changed in this diff Show More