diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index b821e0263ed..76f48b07f6d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -916,7 +916,7 @@ public class FunctionCodegen { @NotNull MethodContext context, @NotNull MemberCodegen parentCodegen ) { - Method delegateToMethod = typeMapper.mapSignature(delegatedTo).getAsmMethod(); + Method delegateToMethod = typeMapper.mapToCallableMethod(delegatedTo, /* superCall = */ false).getAsmMethod(); Method delegateMethod = typeMapper.mapSignature(delegateFunction).getAsmMethod(); Type[] argTypes = delegateMethod.getArgumentTypes(); diff --git a/compiler/testData/codegen/box/bridges/delegationComplex.kt b/compiler/testData/codegen/box/bridges/delegationComplex.kt new file mode 100644 index 00000000000..77af8d7e9b5 --- /dev/null +++ b/compiler/testData/codegen/box/bridges/delegationComplex.kt @@ -0,0 +1,17 @@ +open class Content() { + override fun toString() = "OK" +} + +interface Box { + fun get(): E +} + +interface ContentBox : Box + +object Impl : ContentBox { + override fun get(): Content = Content() +} + +class ContentBoxDelegate() : ContentBox by (Impl as ContentBox) + +fun box() = ContentBoxDelegate().get().toString() diff --git a/compiler/testData/codegen/box/bridges/delegationComplexWithList.kt b/compiler/testData/codegen/box/bridges/delegationComplexWithList.kt new file mode 100644 index 00000000000..9474ef1edad --- /dev/null +++ b/compiler/testData/codegen/box/bridges/delegationComplexWithList.kt @@ -0,0 +1,18 @@ +import java.util.* + +open class Content() { + override fun toString() = "OK" +} + +interface ContentBox : List + +object Impl : ContentBox , AbstractList() { + override fun get(index: Int) = Content() + + override val size: Int + get() = throw UnsupportedOperationException() +} + +class ContentBoxDelegate() : ContentBox by (Impl as ContentBox) + +fun box() = ContentBoxDelegate()[0].toString() diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 7005461a35f..571cd0b2a09 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -418,6 +418,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("delegationComplex.kt") + public void testDelegationComplex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/delegationComplex.kt"); + doTest(fileName); + } + + @TestMetadata("delegationComplexWithList.kt") + public void testDelegationComplexWithList() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/delegationComplexWithList.kt"); + doTest(fileName); + } + @TestMetadata("delegationProperty.kt") public void testDelegationProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/delegationProperty.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BridgeTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BridgeTestGenerated.java index 2c7983e4f61..a9017b84c4b 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BridgeTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BridgeTestGenerated.java @@ -59,6 +59,18 @@ public class BridgeTestGenerated extends AbstractBridgeTest { doTest(fileName); } + @TestMetadata("delegationComplex.kt") + public void testDelegationComplex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/delegationComplex.kt"); + doTest(fileName); + } + + @TestMetadata("delegationComplexWithList.kt") + public void testDelegationComplexWithList() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/delegationComplexWithList.kt"); + doTest(fileName); + } + @TestMetadata("delegationProperty.kt") public void testDelegationProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/delegationProperty.kt");