Support collection literals in the JVM backend
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
import java.util.Arrays
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KFunction0
|
||||
|
||||
inline fun <reified T> test(kFunction: KFunction0<Unit>, test: T.() -> Unit) {
|
||||
val annotation = kFunction.annotations.single() as T
|
||||
annotation.test()
|
||||
}
|
||||
|
||||
fun check(b: Boolean, message: String) {
|
||||
if (!b) throw RuntimeException(message)
|
||||
}
|
||||
|
||||
annotation class Foo(val a: FloatArray = [], val b: Array<String> = [], val c: Array<KClass<*>> = [])
|
||||
|
||||
@Foo(a = [1f, 2f, 1 / 0f])
|
||||
fun test1() {}
|
||||
|
||||
@Foo(b = ["Hello", ", ", "Kot" + "lin"])
|
||||
fun test2() {}
|
||||
|
||||
@Foo(c = [Int::class, Array<Short>::class, Foo::class])
|
||||
fun test3() {}
|
||||
|
||||
fun box(): String {
|
||||
test<Foo>(::test1) {
|
||||
check(a.contentEquals(floatArrayOf(1f, 2f, Float.POSITIVE_INFINITY)), "Fail 1: ${a.joinToString()}")
|
||||
}
|
||||
|
||||
test<Foo>(::test2) {
|
||||
check(b.contentEquals(arrayOf("Hello", ", ", "Kotlin")), "Fail 2: ${b.joinToString()}")
|
||||
}
|
||||
|
||||
test<Foo>(::test3) {
|
||||
check(c.contentEquals(arrayOf(Int::class, Array<Short>::class, Foo::class)), "Fail 3: ${c.joinToString()}")
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
import java.util.Arrays
|
||||
import kotlin.reflect.KFunction0
|
||||
|
||||
inline fun <reified T> test(kFunction: KFunction0<Unit>, test: T.() -> Unit) {
|
||||
val annotation = kFunction.annotations.single() as T
|
||||
annotation.test()
|
||||
}
|
||||
|
||||
fun check(b: Boolean, message: String) {
|
||||
if (!b) throw RuntimeException(message)
|
||||
}
|
||||
|
||||
annotation class Foo(val a: IntArray = [], val b: Array<String> = [])
|
||||
|
||||
const val ONE_INT = 1
|
||||
const val ONE_FLOAT = 1f
|
||||
const val HELLO = "hello"
|
||||
const val C_CHAR = 'c'
|
||||
|
||||
@Foo(
|
||||
a = [ONE_INT, ONE_INT + ONE_FLOAT.toInt(), ONE_INT + 10, (ONE_INT % 1.0).toInt()],
|
||||
b = [HELLO, HELLO + C_CHAR, HELLO + ", Kotlin", C_CHAR.toString() + C_CHAR])
|
||||
fun test1() {}
|
||||
|
||||
fun box(): String {
|
||||
test<Foo>(::test1) {
|
||||
check(a.contentEquals(intArrayOf(1, 2, 11, 0)), "Fail 1: ${a.joinToString()}")
|
||||
check(b.contentEquals(arrayOf("hello", "helloc", "hello, Kotlin", "cc")), "Fail 2: ${b.joinToString()}")
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
import java.util.Arrays
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KFunction0
|
||||
|
||||
inline fun <reified T> test(kFunction: KFunction0<Unit>, test: T.() -> String): String {
|
||||
val annotation = kFunction.annotations.single() as T
|
||||
return annotation.test()
|
||||
}
|
||||
|
||||
fun check(b: Boolean, message: String) {
|
||||
if (!b) throw RuntimeException(message)
|
||||
}
|
||||
|
||||
annotation class Foo(
|
||||
val a: IntArray = [],
|
||||
val b: IntArray = [1, 2, 3],
|
||||
val c: Array<String> = ["/"],
|
||||
val d: Array<KClass<*>> = [Int::class, Array<Int>::class],
|
||||
val e: DoubleArray = [1.0]
|
||||
)
|
||||
|
||||
@Foo
|
||||
fun withAnn() {}
|
||||
|
||||
fun box(): String {
|
||||
return test<Foo>(::withAnn) {
|
||||
check(a.contentEquals(intArrayOf()), "Fail 1: ${a.joinToString()}")
|
||||
check(b.contentEquals(intArrayOf(1, 2, 3)), "Fail 2: ${b.joinToString()}")
|
||||
check(c.contentEquals(arrayOf("/")), "Fail 3: ${c.joinToString()}")
|
||||
check(d.contentEquals(arrayOf(Int::class, Array<Int>::class)), "Fail 4: ${d.joinToString()}")
|
||||
check(e.contentEquals(doubleArrayOf(1.0)), "Fail 5: ${e.joinToString()}")
|
||||
"OK"
|
||||
}
|
||||
}
|
||||
compiler/testData/codegen/light-analysis/collectionLiterals/collectionLiteralsInArgumentPosition.txt
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
@kotlin.Metadata
|
||||
public final class CollectionLiteralsInArgumentPositionKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method check(p0: boolean, @org.jetbrains.annotations.NotNull p1: java.lang.String): void
|
||||
private final static method test(p0: kotlin.reflect.KFunction, p1: kotlin.jvm.functions.Function1): void
|
||||
public final static @Foo method test1(): void
|
||||
public final static @Foo method test2(): void
|
||||
public final static @Foo method test3(): void
|
||||
}
|
||||
|
||||
@java.lang.annotation.Retention
|
||||
@kotlin.Metadata
|
||||
public annotation class Foo {
|
||||
public abstract method a(): float[]
|
||||
public abstract method b(): java.lang.String[]
|
||||
public abstract method c(): java.lang.Class[]
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
@kotlin.Metadata
|
||||
public final class CollectionLiteralsWithConstantsKt {
|
||||
public final static field C_CHAR: char
|
||||
public final static @org.jetbrains.annotations.NotNull field HELLO: java.lang.String
|
||||
public final static field ONE_FLOAT: float
|
||||
public final static field ONE_INT: int
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method check(p0: boolean, @org.jetbrains.annotations.NotNull p1: java.lang.String): void
|
||||
private final static method test(p0: kotlin.reflect.KFunction, p1: kotlin.jvm.functions.Function1): void
|
||||
public final static @Foo method test1(): void
|
||||
}
|
||||
|
||||
@java.lang.annotation.Retention
|
||||
@kotlin.Metadata
|
||||
public annotation class Foo {
|
||||
public abstract method a(): int[]
|
||||
public abstract method b(): java.lang.String[]
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
@kotlin.Metadata
|
||||
public final class DefaultAnnotationParameterValuesKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method check(p0: boolean, @org.jetbrains.annotations.NotNull p1: java.lang.String): void
|
||||
private final static method test(p0: kotlin.reflect.KFunction, p1: kotlin.jvm.functions.Function1): java.lang.String
|
||||
public final static @Foo method withAnn(): void
|
||||
}
|
||||
|
||||
@java.lang.annotation.Retention
|
||||
@kotlin.Metadata
|
||||
public annotation class Foo {
|
||||
public abstract method a(): int[]
|
||||
public abstract method b(): int[]
|
||||
public abstract method c(): java.lang.String[]
|
||||
public abstract method d(): java.lang.Class[]
|
||||
public abstract method e(): double[]
|
||||
}
|
||||
Reference in New Issue
Block a user