diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java index 348c526a932..dccbe67d9ea 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java @@ -179,24 +179,24 @@ public class ResolutionResultsHandler { return OverloadResolutionResultsImpl.success(candidates.iterator().next()); } - MutableResolvedCall maximallySpecific = OverloadingConflictResolver.INSTANCE.findMaximallySpecific(candidates, false); + Set> noOverrides = OverrideResolver.filterOutOverridden(candidates, MAP_TO_RESULT); + if (noOverrides.size() == 1) { + return OverloadResolutionResultsImpl.success(noOverrides.iterator().next()); + } + + MutableResolvedCall maximallySpecific = OverloadingConflictResolver.INSTANCE.findMaximallySpecific(noOverrides, false); if (maximallySpecific != null) { return OverloadResolutionResultsImpl.success(maximallySpecific); } if (discriminateGenerics) { MutableResolvedCall maximallySpecificGenericsDiscriminated = OverloadingConflictResolver.INSTANCE.findMaximallySpecific( - candidates, true); + noOverrides, true); if (maximallySpecificGenericsDiscriminated != null) { return OverloadResolutionResultsImpl.success(maximallySpecificGenericsDiscriminated); } } - Set> noOverrides = OverrideResolver.filterOutOverridden(candidates, MAP_TO_RESULT); - if (noOverrides.size() == 1) { - return OverloadResolutionResultsImpl.success(noOverrides.iterator().next()); - } - return OverloadResolutionResultsImpl.ambiguity(noOverrides); } diff --git a/compiler/testData/diagnostics/tests/multimodule/varargConflict.kt b/compiler/testData/diagnostics/tests/multimodule/varargConflict.kt new file mode 100644 index 00000000000..0631d24ad78 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/varargConflict.kt @@ -0,0 +1,26 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// MODULE: m1 +// FILE: a.kt + +package p + +public fun foo(a: Int) {} +public fun foo(vararg values: Int) {} + +// MODULE: m2 +// FILE: b.kt + +package p + +public fun foo(a: Int) {} +public fun foo(vararg values: Int) {} + +// MODULE: m3(m1, m2) +// FILE: c.kt +package m + +import p.foo + +fun main() { + foo(12) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/multimodule/varargConflict.txt b/compiler/testData/diagnostics/tests/multimodule/varargConflict.txt new file mode 100644 index 00000000000..148397c48a3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multimodule/varargConflict.txt @@ -0,0 +1,33 @@ +// -- Module: -- +package + +package p { + public fun foo(/*0*/ a: kotlin.Int): kotlin.Unit + public fun foo(/*0*/ vararg values: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit +} + + +// -- Module: -- +package + +package p { + public fun foo(/*0*/ a: kotlin.Int): kotlin.Unit + public fun foo(/*0*/ vararg values: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit +} + + +// -- Module: -- +package + +package m { + internal fun main(): kotlin.Unit +} + +package p { + public fun foo(/*0*/ a: kotlin.Int): kotlin.Unit + public fun foo(/*0*/ a: kotlin.Int): kotlin.Unit + public fun foo(/*0*/ vararg values: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit + public fun foo(/*0*/ vararg values: kotlin.Int /*kotlin.IntArray*/): kotlin.Unit +} + + diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index ff2bcebd025..7f828debc5d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -8388,6 +8388,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("varargConflict.kt") + public void testVarargConflict() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multimodule/varargConflict.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/diagnostics/tests/multimodule/duplicateClass") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)