diff --git a/compiler/testData/codegen/box/collectionLiterals/collectionLiteralsWithVarargs.kt b/compiler/testData/codegen/box/collectionLiterals/collectionLiteralsWithVarargs.kt new file mode 100644 index 00000000000..a0e15d7948b --- /dev/null +++ b/compiler/testData/codegen/box/collectionLiterals/collectionLiteralsWithVarargs.kt @@ -0,0 +1,42 @@ +// WITH_REFLECT + +// IGNORE_BACKEND: JS + +import java.util.Arrays +import kotlin.reflect.KClass +import kotlin.reflect.KFunction0 + +inline fun test(kFunction: KFunction0, test: T.() -> Unit) { + val annotation = kFunction.annotations.single() as T + annotation.test() +} + +fun check(b: Boolean, message: String) { + if (!b) throw RuntimeException(message) +} + +@Suppress("UNSUPPORTED_FEATURE") +annotation class Foo(vararg val a: String = ["a", "b"]) + +@Suppress("UNSUPPORTED_FEATURE") +annotation class Bar(vararg val a: KClass<*> = [Int::class]) + +@Suppress("UNSUPPORTED_FEATURE") +@Foo(*["/"]) +fun test1() {} + +@Suppress("UNSUPPORTED_FEATURE") +@Bar(*[Long::class, String::class]) +fun test2() {} + +fun box(): String { + test(::test1) { + check(a.contentEquals(arrayOf("/")), "Fail 1: ${a.joinToString()}") + } + + test(::test2) { + check(a.contentEquals(arrayOf(Long::class, String::class)), "Fail 2: ${a.joinToString()}") + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.kt b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.kt new file mode 100644 index 00000000000..f91f05ed3a4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.kt @@ -0,0 +1,40 @@ +// !LANGUAGE: +ArrayLiteralsInAnnotations + +annotation class Ann1(vararg val a: String = []) +annotation class Ann2(vararg val a: Int = [1, 2]) +annotation class Ann3(vararg val a: Float = [1f]) +annotation class Ann4(vararg val a: String = ["/"]) + +annotation class Ann5(vararg val a: Ann4 = []) +annotation class Ann6(vararg val a: Ann4 = [Ann4(*["a", "b"])]) + +annotation class Ann7(vararg val a: Long = [1L, null, ""]) + +@Ann1(*[]) +fun test1_0() {} + +@Ann1(*["a", "b"]) +fun test1_1() {} + +@Ann1(*["a", 1, null]) +fun test1_2() {} + +@Ann2(*[]) +fun test2() {} + +@Ann3(a = *[0f, 1 / 0f]) +fun test3() {} + +@Ann5(Ann4(*["/"])) +fun test5() {} + +@Ann6(*[]) +fun test6() {} + +annotation class AnnArray(val a: Array) + +@AnnArray(*["/"]) +fun testArray() {} + +@Ann1([""]) +fun testVararg() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.txt b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.txt new file mode 100644 index 00000000000..181267ed42e --- /dev/null +++ b/compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.txt @@ -0,0 +1,75 @@ +package + +@Ann1(a = {}) public fun test1_0(): kotlin.Unit +@Ann1(a = {"a", "b"}) public fun test1_1(): kotlin.Unit +@Ann1(a = {"a", 1, null}) public fun test1_2(): kotlin.Unit +@Ann2(a = {}) public fun test2(): kotlin.Unit +@Ann3(a = {0.0.toFloat(), Infinity.toFloat()}) public fun test3(): kotlin.Unit +@Ann5(a = {Ann4(a = {"/"})}) public fun test5(): kotlin.Unit +@Ann6(a = {}) public fun test6(): kotlin.Unit +@AnnArray(a = {"/"}) public fun testArray(): kotlin.Unit +@Ann1(a = {{""}}) public fun testVararg(): kotlin.Unit + +public final annotation class Ann1 : kotlin.Annotation { + public constructor Ann1(/*0*/ vararg a: kotlin.String /*kotlin.Array*/ = ...) + public final val a: kotlin.Array + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class Ann2 : kotlin.Annotation { + public constructor Ann2(/*0*/ vararg a: kotlin.Int /*kotlin.IntArray*/ = ...) + public final val a: kotlin.IntArray + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class Ann3 : kotlin.Annotation { + public constructor Ann3(/*0*/ vararg a: kotlin.Float /*kotlin.FloatArray*/ = ...) + public final val a: kotlin.FloatArray + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class Ann4 : kotlin.Annotation { + public constructor Ann4(/*0*/ vararg a: kotlin.String /*kotlin.Array*/ = ...) + public final val a: kotlin.Array + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class Ann5 : kotlin.Annotation { + public constructor Ann5(/*0*/ vararg a: Ann4 /*kotlin.Array*/ = ...) + public final val a: kotlin.Array + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class Ann6 : kotlin.Annotation { + public constructor Ann6(/*0*/ vararg a: Ann4 /*kotlin.Array*/ = ...) + public final val a: kotlin.Array + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class Ann7 : kotlin.Annotation { + public constructor Ann7(/*0*/ vararg a: kotlin.Long /*kotlin.LongArray*/ = ...) + public final val a: kotlin.LongArray + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class AnnArray : kotlin.Annotation { + public constructor AnnArray(/*0*/ a: kotlin.Array) + public final val a: kotlin.Array + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index f9c09810a0b..5f8d8ce2c30 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -3914,6 +3914,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("collectionLiteralsWithVarargs.kt") + public void testCollectionLiteralsWithVarargs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collectionLiterals/collectionLiteralsWithVarargs.kt"); + doTest(fileName); + } + @TestMetadata("defaultAnnotationParameterValues.kt") public void testDefaultAnnotationParameterValues() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collectionLiterals/defaultAnnotationParameterValues.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index fb90878b0c7..c53c6dddecb 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -3364,6 +3364,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("collectionLiteralsWithVarargs.kt") + public void testCollectionLiteralsWithVarargs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/collectionLiterals/collectionLiteralsWithVarargs.kt"); + doTest(fileName); + } + @TestMetadata("defaultValuesInAnnotation.kt") public void testDefaultValuesInAnnotation() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 90afc1bf5c3..42006c1342e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -3914,6 +3914,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("collectionLiteralsWithVarargs.kt") + public void testCollectionLiteralsWithVarargs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collectionLiterals/collectionLiteralsWithVarargs.kt"); + doTest(fileName); + } + @TestMetadata("defaultAnnotationParameterValues.kt") public void testDefaultAnnotationParameterValues() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collectionLiterals/defaultAnnotationParameterValues.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 3caf092b431..1cc12a40535 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -3914,6 +3914,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("collectionLiteralsWithVarargs.kt") + public void testCollectionLiteralsWithVarargs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collectionLiterals/collectionLiteralsWithVarargs.kt"); + doTest(fileName); + } + @TestMetadata("defaultAnnotationParameterValues.kt") public void testDefaultAnnotationParameterValues() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collectionLiterals/defaultAnnotationParameterValues.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 63f2c304f59..17e3873aad4 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -4587,6 +4587,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } + @TestMetadata("collectionLiteralsWithVarargs.kt") + public void testCollectionLiteralsWithVarargs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collectionLiterals/collectionLiteralsWithVarargs.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + @TestMetadata("defaultAnnotationParameterValues.kt") public void testDefaultAnnotationParameterValues() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collectionLiterals/defaultAnnotationParameterValues.kt");