diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index fc6d6776d28..a952004557f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -457,7 +457,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } if (!hasGenericToArray) { - MethodVisitor mv = v.newMethod(NO_ORIGIN, ACC_PUBLIC, "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;", null, null); + MethodVisitor mv = v.newMethod( + NO_ORIGIN, ACC_PUBLIC, "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;", "([TT;)[TT;", null); InstructionAdapter iv = new InstructionAdapter(mv); mv.visitCode(); diff --git a/compiler/testData/codegen/box/collections/toArrayInJavaClass.kt b/compiler/testData/codegen/box/collections/toArrayInJavaClass.kt new file mode 100644 index 00000000000..96884be824a --- /dev/null +++ b/compiler/testData/codegen/box/collections/toArrayInJavaClass.kt @@ -0,0 +1,32 @@ +// WITH_RUNTIME +// FILE: B.java +public class B extends A { + @Override + public T[] toArray(T[] a) { + return a; + } +} + +// FILE: main.kt +open class A : Collection { + override val size: Int + get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. + + override fun contains(element: T): Boolean { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun containsAll(elements: Collection): Boolean { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun isEmpty(): Boolean { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun iterator(): Iterator { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun box() = B().toArray(arrayOf("OK"))[0] diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index cdd4d4f8ad7..59c0c288c2e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -3615,6 +3615,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collections/strList.kt"); doTest(fileName); } + + @TestMetadata("toArrayInJavaClass.kt") + public void testToArrayInJavaClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collections/toArrayInJavaClass.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/compatibility")