Support instantiation of annotations in JS
#KT-47700 Fixed
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// IGNORE_BACKEND: WASM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
// !LANGUAGE: +InstantiationOfAnnotationClasses
|
||||
@@ -22,7 +25,7 @@ data class BarLike(val i:Int, val s: String, val f: Float)
|
||||
fun box(): String {
|
||||
val foo1 = Foo(42, "foo", arrayOf("a", "b"), intArrayOf(1,2), Bar::class, Bar(10, "bar", Float.NaN))
|
||||
val foo2 = Foo(42, "foo", arrayOf("a", "b"), intArrayOf(1,2), Bar::class, Bar(10, "bar", Float.NaN))
|
||||
if (foo1 != foo2) return "Failed equals"
|
||||
if (foo1 != foo2) return "Failed equals ${foo1.toString()} ${foo2.toString()}"
|
||||
val barlike = BarLike(10, "bar", Float.NaN)
|
||||
if (barlike.hashCode() != foo1.bar.hashCode()) return "Failed HC1"
|
||||
if (barlike.hashCode() != foo2.bar.hashCode()) return "Failed HC2"
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// IGNORE_BACKEND: WASM
|
||||
|
||||
// (supported: JVM_IR, JS_IR(_E6))
|
||||
// Regular JS works too, but without proper hashCode or equals
|
||||
|
||||
// WITH_RUNTIME
|
||||
// !LANGUAGE: +InstantiationOfAnnotationClasses
|
||||
@@ -7,6 +12,7 @@
|
||||
// note: taken from ../parameters.kt and ../parametersWithPrimitiveValues.kt
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue as assert
|
||||
|
||||
enum class E { E0 }
|
||||
annotation class Empty
|
||||
|
||||
+15
-3
@@ -1,5 +1,8 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// IGNORE_BACKEND: WASM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
// !LANGUAGE: +InstantiationOfAnnotationClasses
|
||||
@@ -7,6 +10,8 @@
|
||||
package test
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertTrue as assert
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
enum class E { A, B }
|
||||
|
||||
@@ -31,8 +36,15 @@ annotation class Partial(
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
assert(c.toString() == "@test.C(i=42, b=@test.B(a=@test.A()), kClass=interface test.B (Kotlin reflection is not available), e=B, aS=[a, b], aI=[1, 2])")
|
||||
assertEquals(42, c.i)
|
||||
assertEquals(A(), c.b.a)
|
||||
assertEquals(B::class, c.kClass)
|
||||
assertEquals(E.B, c.e)
|
||||
assert(arrayOf("a", "b").contentEquals(c.aS))
|
||||
assert(intArrayOf(1, 2).contentEquals(c.aI))
|
||||
val p = Partial(e = E.B, s = "bar")
|
||||
assert(p.toString() == "@test.Partial(i=42, s=bar, e=B)")
|
||||
assertEquals(42, p.i)
|
||||
assertEquals("bar", p.s)
|
||||
assertEquals(E.B, p.e)
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// IGNORE_BACKEND: WASM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
// !LANGUAGE: +InstantiationOfAnnotationClasses
|
||||
@@ -22,7 +25,6 @@ annotation class A(
|
||||
val bool: Boolean
|
||||
)
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Anno(
|
||||
val s: String,
|
||||
val i: Int,
|
||||
@@ -44,7 +46,8 @@ fun box(): String {
|
||||
A::class, emptyArray(), intArrayOf(1, 2), arrayOf(E.E0), arrayOf(Empty())
|
||||
)
|
||||
val s = anno.toString()
|
||||
val target = "@test.Anno(s=OK, i=42, f=2.718281828, u=43, e=E0, a=@test.A(b=1, s=1, i=1, f=1.0, d=1.0, l=1, c=c, bool=true), " +
|
||||
val targetJVM = "@test.Anno(s=OK, i=42, f=2.718281828, u=43, e=E0, a=@test.A(b=1, s=1, i=1, f=1.0, d=1.0, l=1, c=c, bool=true), " +
|
||||
"k=interface test.A (Kotlin reflection is not available), arr=[], intArr=[1, 2], arrOfE=[E0], arrOfA=[@test.Empty()])"
|
||||
return if (s == target) "OK" else "FAILED, got string $s"
|
||||
val targetJS = "@test.Anno(s=OK, i=42, f=2.718281828, u=43, e=E0, a=@test.A(b=1, s=1, i=1, f=1, d=1, l=1, c=c, bool=true), k=class A, arr=[...], intArr=[...], arrOfE=[...], arrOfA=[...])"
|
||||
return if (s == targetJS || s == targetJVM) "OK" else "FAILED, got string $s"
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// IGNORE_BACKEND: WASM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
|
||||
// (supported: JVM_IR, JS_IR(_E6))
|
||||
|
||||
// WITH_RUNTIME
|
||||
// !LANGUAGE: +InstantiationOfAnnotationClasses
|
||||
|
||||
+5
-1
@@ -1,5 +1,9 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// IGNORE_BACKEND: WASM
|
||||
|
||||
// (supported: JVM_IR, JS_IR(_E6))
|
||||
|
||||
// WITH_RUNTIME
|
||||
// !LANGUAGE: +InstantiationOfAnnotationClasses +MultiPlatformProjects
|
||||
|
||||
Reference in New Issue
Block a user