From 82a5beddeac54cbad5dc04e8a42ca39e51ecc1f2 Mon Sep 17 00:00:00 2001 From: Kirill Berezin Date: Sun, 26 Aug 2012 18:39:34 +0400 Subject: [PATCH] do not copy overrides for the delegated methods, it causes failure of delegation to traits which extend other traits --- .../jet/lang/resolve/DelegationResolver.java | 2 +- .../testData/codegen/classes/delegation4.kt | 28 +++++++++++++++++++ .../jetbrains/jet/codegen/ClassGenTest.java | 5 ++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/classes/delegation4.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java index 17c53781d59..2eeb5679187 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java @@ -124,7 +124,7 @@ public class DelegationResolver { if (memberDescriptor.getModality().isOverridable()) { Modality modality = DescriptorUtils.convertModality(memberDescriptor.getModality(), true); CallableMemberDescriptor copy = - memberDescriptor.copy(newOwner, modality, false, CallableMemberDescriptor.Kind.DELEGATION, true); + memberDescriptor.copy(newOwner, modality, false, CallableMemberDescriptor.Kind.DELEGATION, false); result.add(copy); } } diff --git a/compiler/testData/codegen/classes/delegation4.kt b/compiler/testData/codegen/classes/delegation4.kt new file mode 100644 index 00000000000..9cf5f0eaf61 --- /dev/null +++ b/compiler/testData/codegen/classes/delegation4.kt @@ -0,0 +1,28 @@ +open trait First { + public open fun foo() : Int +} + +open trait Second : First { + public open fun bar() : Int +} + +class Impl : Second { + public override fun foo() = 1 + public override fun bar() = 2 +} + +class Test(s : Second) : Second by s {} + +fun box() : String { + var t = Test(Impl()) + if (t.foo() != 1) + return "Fail #1" + if (t.bar() != 2) + return "Fail #2" + if (t !is First) + return "Fail #3" + if (t !is Second) + return "Fail #4" + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java index 7480bf4db99..854532f7079 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java @@ -73,6 +73,11 @@ public class ClassGenTest extends CodegenTestCase { blackBoxFile("classes/delegation3.kt"); } + public void testInheritanceAndDelegation4() throws Exception { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("classes/delegation4.kt"); + } + public void testFunDelegation() throws Exception { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); blackBoxFile("classes/funDelegation.jet");