Add tests for type annotations with unresolved reference and invalid target (KT-28424, KT-28449)
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 1
|
||||
* DESCRIPTION: Type annotations on return type with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann
|
||||
|
||||
fun foo(x: String): @Ann(unresolved_reference) String { // OK, error only in IDE but not in the compiler
|
||||
return x
|
||||
}
|
||||
|
||||
fun box(): String? {
|
||||
return "OK"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 10
|
||||
* DESCRIPTION: Type annotations on a lambda type with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann(val x: Int)
|
||||
|
||||
fun case_1(): Any {
|
||||
val x: (Int) -> @Ann(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) Unit = {} // OK, no error in IDE and in the compiler
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
fun case_2(): Any {
|
||||
val x: (@Ann(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) Int) -> Unit = { a: Int -> println(a) } // OK, no error in IDE and in the compiler
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
fun box(): String? {
|
||||
val x = case_1()
|
||||
val y = case_2()
|
||||
|
||||
if (x == null) return null
|
||||
if (y == null) return null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 11
|
||||
* DESCRIPTION: Type annotations with invalid target.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28449
|
||||
*/
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Target(AnnotationTarget.PROPERTY_GETTER)
|
||||
annotation class Ann(val x: Int)
|
||||
|
||||
class Foo : @<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>(10) Any()
|
||||
|
||||
class Bar<T : @Ann(10) Any>
|
||||
|
||||
fun case_3(a: Any): Int? {
|
||||
return if (a is @Ann(10) String) 10 else null
|
||||
}
|
||||
|
||||
open class TypeToken<T>
|
||||
|
||||
val case_4 = object : TypeToken<@<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>(10) String>() {}
|
||||
|
||||
fun case_5(a: Any): Any {
|
||||
a as @<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>(10) Int
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
fun box(): String? {
|
||||
val x1 = Foo()
|
||||
val x2 = Bar<Int>()
|
||||
val x3 = case_3(".")
|
||||
val x4 = case_4
|
||||
val x5 = case_5(10)
|
||||
|
||||
if (x1 == null) return null
|
||||
if (x2 == null) return null
|
||||
if (x3 == null) return null
|
||||
if (x4 == null) return null
|
||||
if (x5 == null) return null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 2
|
||||
* DESCRIPTION: Type annotations on supertypes with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann(val x: Int)
|
||||
|
||||
abstract class Foo : @<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) Any()
|
||||
|
||||
class Bar: Foo()
|
||||
|
||||
fun box(): String? {
|
||||
val x = Bar()
|
||||
|
||||
if (x == null) return null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 3
|
||||
* DESCRIPTION: Type annotations on parameter types with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann(val x: Int)
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun foo(i: Inv<@Ann(<!UNRESOLVED_REFERENCE!>unresolved_reference<!>) String>) {}
|
||||
|
||||
fun bar(vararg a: @Ann(<!UNRESOLVED_REFERENCE!>unresolved_reference<!>) Any) {}
|
||||
|
||||
class A<T>(a: @Ann(<!UNRESOLVED_REFERENCE!>unresolved_reference<!>) T)
|
||||
|
||||
fun box(): String? {
|
||||
val x = foo(Inv<String>())
|
||||
val y = bar(1, 2, 3)
|
||||
val z = A<Int>(10)
|
||||
|
||||
if (x == null) return null
|
||||
if (y == null) return null
|
||||
if (z == null) return null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 4
|
||||
* DESCRIPTION: Type annotations on type arguments for a containing type of return type, with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann(val x: Int)
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun case_1(): Inv<@Ann(<!UNRESOLVED_REFERENCE!>unresolved_reference<!>) String> = TODO()
|
||||
|
||||
fun box(): String? {
|
||||
try {
|
||||
val x = case_1()
|
||||
if (x == null) return null
|
||||
} catch (e: NotImplementedError) {}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 5
|
||||
* DESCRIPTION: Type annotations on upper bounds with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann(val x: Int)
|
||||
|
||||
abstract class Bar<T : @Ann(<!UNRESOLVED_REFERENCE!>unresolved_reference<!>) Any>
|
||||
|
||||
class Foo<T : Any> : Bar<T>()
|
||||
|
||||
class B<T> where @<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) T : Number
|
||||
|
||||
fun box(): String? {
|
||||
val x = Foo<Int>()
|
||||
val y = B<Float>()
|
||||
|
||||
if (x == null) return null
|
||||
if (y == null) return null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 6
|
||||
* DESCRIPTION: Type annotations inside type check and cast expression with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann(val x: Int)
|
||||
|
||||
fun case_1(a: Any): Int? {
|
||||
return if (a is @Ann(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) String) 10 else null
|
||||
}
|
||||
|
||||
fun case_2(a: Any): Any {
|
||||
return a as @<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) String // OK, no error in IDE and in the compiler
|
||||
}
|
||||
|
||||
fun case_3_1(a: Any) = 10
|
||||
|
||||
fun case_3(a: Any): Any {
|
||||
return case_3_1(a as @<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) String) // OK, no error in IDE and in the compiler
|
||||
}
|
||||
|
||||
fun box(): String? {
|
||||
val x = case_1(".")
|
||||
val y = case_2(".")
|
||||
val z = case_3(".")
|
||||
|
||||
if (x == null) return null
|
||||
if (y == null) return null
|
||||
if (z == null) return null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 7
|
||||
* DESCRIPTION: Type annotations on a type in an anonymous object expression, with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann
|
||||
|
||||
open class TypeToken<T>
|
||||
|
||||
val case_1 = object : TypeToken<@<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) String>() {}
|
||||
|
||||
interface A
|
||||
|
||||
val case_2 = object: @<!DEBUG_INFO_MISSING_UNRESOLVED!>Ann<!>(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) A {}
|
||||
|
||||
fun box(): String? {
|
||||
val x = case_1
|
||||
val y = case_2
|
||||
|
||||
if (x == null) return null
|
||||
if (y == null) return null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 8
|
||||
* DESCRIPTION: Type annotations on a receiver type (for an extension property only), with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann(val x: Int)
|
||||
|
||||
val <T> @Ann(<!UNRESOLVED_REFERENCE!>unresolved_reference<!>) T.test // OK, error only in IDE but not in the compiler
|
||||
get() = 10
|
||||
|
||||
val @Ann(<!UNRESOLVED_REFERENCE!>unresolved_reference<!>) Int.test
|
||||
get() = 10
|
||||
|
||||
fun box(): String? {
|
||||
val x = 10.test
|
||||
val y = '.'.test
|
||||
|
||||
if (x == null) return null
|
||||
if (y == null) return null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SECTIONS: annotations, type-annotations
|
||||
* NUMBER: 9
|
||||
* DESCRIPTION: Type annotations on a setter argument type with unresolved reference in parameters.
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-28424
|
||||
*/
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Ann
|
||||
|
||||
var <T> T.test
|
||||
get() = 11
|
||||
set(value: @Ann(<!DEBUG_INFO_MISSING_UNRESOLVED!>unresolved_reference<!>) Int) {}
|
||||
|
||||
fun box(): String? {
|
||||
val x = 10.test
|
||||
10.test = 11
|
||||
val y = 10.test
|
||||
|
||||
if (x == null) return null
|
||||
if (y == null) return null
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user