Value classes: Allow unsigned arrays in annotations

including varargs, apparently.
So, we allow unsigned types and unsigned arrays in annotations,
but disallow user-defined inline classes.
 #KT-23816 Fixed
This commit is contained in:
Ilmir Usmanov
2020-12-02 20:14:43 +01:00
parent a9c072f826
commit 516fce37db
16 changed files with 229 additions and 8 deletions
@@ -0,0 +1,68 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_REFLECT
// TARGET_BACKEND: JVM
annotation class AnnoUB(val ub: UByteArray)
annotation class AnnoUS(val us: UShortArray)
annotation class AnnoUI(val ui: UIntArray)
annotation class AnnoUL(val ul: ULongArray)
@Suppress("INVISIBLE_MEMBER")
const val ub0 = UByte(1)
@Suppress("INVISIBLE_MEMBER")
const val us0 = UShort(2)
@Suppress("INVISIBLE_MEMBER")
const val ul0 = ULong(3)
@Suppress("INVISIBLE_MEMBER")
const val ui0 = UInt(-1)
@Suppress("INVISIBLE_MEMBER")
const val ui1 = UInt(0)
@Suppress("INVISIBLE_MEMBER")
const val ui2 = UInt(40 + 2)
@Suppress("INVISIBLE_MEMBER")
object Foo {
@AnnoUB([UByte(1), ub0])
fun f0() {}
@AnnoUS([UShort(2 + 5), us0])
fun f1() {}
@AnnoUI([ui0, ui1, ui2, UInt(100)])
fun f2() {}
@AnnoUL([ul0, ULong(5)])
fun f3() {}
}
fun <T> check(ann: Annotation, f: T.() -> Boolean) {
val result = (ann as T).f()
if (!result) throw RuntimeException("fail for $ann")
}
@Suppress("INVISIBLE_MEMBER")
fun box(): String {
if (ub0.toByte() != 1.toByte()) return "fail"
if (us0.toShort() != 2.toShort()) return "fail"
if (ul0.toLong() != 3L) return "fail"
if ((ui0 + ui1 + ui2).toInt() != 41) return "fail"
check<AnnoUB>(Foo::f0.annotations.first()) {
this.ub[0] == UByte(1) && this.ub[1] == UByte(1)
}
check<AnnoUS>(Foo::f1.annotations.first()) {
this.us[0] == UShort(7) && this.us[1] == UShort(2)
}
check<AnnoUI>(Foo::f2.annotations.first()) {
this.ui[0] == UInt.MAX_VALUE && this.ui[1] == UInt(0) && this.ui[2] == UInt(42) && this.ui[3] == UInt(100)
}
check<AnnoUL>(Foo::f3.annotations.first()) {
this.ul[0] == ULong(3) && this.ul[1] == ULong(5)
}
return "OK"
}
@@ -0,0 +1,19 @@
// !LANGUAGE: +InlineClasses
// WITH_RUNTIME
annotation class Ann(
val u: UInt,
val uba: UByteArray,
val usa: UShortArray,
val uia: UIntArray,
val ula: ULongArray
)
@Ann(
1u,
[1u],
ushortArrayOf(),
[1u, 1u],
ulongArrayOf(1u, 1u)
)
fun foo() {}
@@ -0,0 +1,16 @@
@java.lang.annotation.Retention
@kotlin.Metadata
public annotation class Ann {
// source: 'annotationGetters.kt'
public abstract method u(): int
public abstract method uba(): byte[]
public abstract method uia(): int[]
public abstract method ula(): long[]
public abstract method usa(): short[]
}
@kotlin.Metadata
public final class AnnotationGettersKt {
// source: 'annotationGetters.kt'
public final static @Ann method foo(): void
}