From 51a6bcb7273f2e484ec60a667efdf176af3092a4 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 17 Sep 2013 16:18:39 +0400 Subject: [PATCH] Test for reporting clashes with multiple delegated methods Verifies that the order in which traits are inherited is irrelevant --- .../jet/lang/resolve/DelegationResolver.java | 1 + .../tests/Delegation_ClashingFunctions.kt | 17 +++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 23 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/Delegation_ClashingFunctions.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 47bd0e9a1e4..291cfe76aef 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java @@ -219,6 +219,7 @@ public final class DelegationResolver { } private static boolean haveSameSignatures(@NotNull CallableDescriptor memberOne, @NotNull CallableDescriptor memberTwo) { + //isOverridableBy ignores return types return OverridingUtil.isOverridableBy(memberOne, memberTwo).getResult() == OVERRIDABLE; } diff --git a/compiler/testData/diagnostics/tests/Delegation_ClashingFunctions.kt b/compiler/testData/diagnostics/tests/Delegation_ClashingFunctions.kt new file mode 100644 index 00000000000..ae8b3dabfeb --- /dev/null +++ b/compiler/testData/diagnostics/tests/Delegation_ClashingFunctions.kt @@ -0,0 +1,17 @@ +trait One { + public fun foo(): Any? +} +trait Two { + public fun foo(): String? +} + +trait Three { + public fun foo(): String +} + +class Test123(val v1: One, val v2: Two, val v3: Three) : One by v1, Two by v2, Three by v3 { } +class Test132(val v1: One, val v2: Two, val v3: Three) : One by v1, Three by v3, Two by v2 { } +class Test312(val v1: One, val v2: Two, val v3: Three) : Three by v3, One by v1, Two by v2 { } +class Test321(val v1: One, val v2: Two, val v3: Three) : Three by v3, Two by v2, One by v1 { } +class Test231(val v1: One, val v2: Two, val v3: Three) : Two by v2, Three by v3, One by v1 { } +class Test213(val v1: One, val v2: Two, val v3: Three) : Two by v2, One by v1, Three by v3 { } \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index c142a5a186a..efb3b8316be 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -194,6 +194,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/DelegationToJavaIface.kt"); } + @TestMetadata("Delegation_ClashingFunctions.kt") + public void testDelegation_ClashingFunctions() throws Exception { + doTest("compiler/testData/diagnostics/tests/Delegation_ClashingFunctions.kt"); + } + @TestMetadata("Delegation_Hierarchy.kt") public void testDelegation_Hierarchy() throws Exception { doTest("compiler/testData/diagnostics/tests/Delegation_Hierarchy.kt");