Filter out overridden candidates before looking for most specific
This filtering will remove signature duplicates that prevent findMaximallySpecific() from finding best candidate.
This commit is contained in:
+7
-7
@@ -179,24 +179,24 @@ public class ResolutionResultsHandler {
|
||||
return OverloadResolutionResultsImpl.success(candidates.iterator().next());
|
||||
}
|
||||
|
||||
MutableResolvedCall<D> maximallySpecific = OverloadingConflictResolver.INSTANCE.findMaximallySpecific(candidates, false);
|
||||
Set<MutableResolvedCall<D>> noOverrides = OverrideResolver.filterOutOverridden(candidates, MAP_TO_RESULT);
|
||||
if (noOverrides.size() == 1) {
|
||||
return OverloadResolutionResultsImpl.success(noOverrides.iterator().next());
|
||||
}
|
||||
|
||||
MutableResolvedCall<D> maximallySpecific = OverloadingConflictResolver.INSTANCE.findMaximallySpecific(noOverrides, false);
|
||||
if (maximallySpecific != null) {
|
||||
return OverloadResolutionResultsImpl.success(maximallySpecific);
|
||||
}
|
||||
|
||||
if (discriminateGenerics) {
|
||||
MutableResolvedCall<D> maximallySpecificGenericsDiscriminated = OverloadingConflictResolver.INSTANCE.findMaximallySpecific(
|
||||
candidates, true);
|
||||
noOverrides, true);
|
||||
if (maximallySpecificGenericsDiscriminated != null) {
|
||||
return OverloadResolutionResultsImpl.success(maximallySpecificGenericsDiscriminated);
|
||||
}
|
||||
}
|
||||
|
||||
Set<MutableResolvedCall<D>> noOverrides = OverrideResolver.filterOutOverridden(candidates, MAP_TO_RESULT);
|
||||
if (noOverrides.size() == 1) {
|
||||
return OverloadResolutionResultsImpl.success(noOverrides.iterator().next());
|
||||
}
|
||||
|
||||
return OverloadResolutionResultsImpl.ambiguity(noOverrides);
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// -- Module: <m1> --
|
||||
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: <m2> --
|
||||
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: <m3> --
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user