diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index 55f7ce4d898..1fb2f6a51df 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -93,7 +93,7 @@ class FirCallResolver( val reducedCandidates = if (result.currentApplicability < CandidateApplicability.SYNTHETIC_RESOLVED) { bestCandidates.toSet() } else { - conflictResolver.chooseMaximallySpecificCandidates(bestCandidates, discriminateGenerics = false) + conflictResolver.chooseMaximallySpecificCandidates(bestCandidates, discriminateGenerics = true) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt index 4a54310807c..94db1c14ce4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt @@ -33,19 +33,19 @@ class ConeOverloadConflictResolver( fun chooseMaximallySpecificCandidates( candidates: Collection, //checkArgumentsMode: CheckArgumentTypesMode, - discriminateGenerics: Boolean//, - //isDebuggerContext: Boolean + discriminateGenerics: Boolean ): Set { + candidates.setIfOneOrEmpty()?.let { return it } val candidatesSet = candidates.toSet() - val maximallySpecific = findMaximallySpecificCall(candidatesSet, false/*, isDebuggerContext*/) - if (maximallySpecific != null) { - return setOf(maximallySpecific) + findMaximallySpecificCall(candidatesSet, false)?.let { return setOf(it) } + + if (discriminateGenerics) { + findMaximallySpecificCall(candidatesSet, true)?.let { return setOf(it) } } return candidatesSet - } private fun createFlatSignature(call: Candidate): FlatSignature { @@ -224,6 +224,11 @@ class ConeOverloadConflictResolver( return true } + private fun Collection.setIfOneOrEmpty(): Set? = when (size) { + 0 -> emptySet() + 1 -> setOf(single()) + else -> null + } } object NoSubstitutor : TypeSubstitutorMarker diff --git a/compiler/fir/resolve/testData/resolve/arguments/overloadByReceiver.kt b/compiler/fir/resolve/testData/resolve/arguments/overloadByReceiver.kt new file mode 100644 index 00000000000..f8b42bbf33f --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/arguments/overloadByReceiver.kt @@ -0,0 +1,17 @@ +interface A + +interface B : A + +interface C + +interface D : B, C + +fun B.foo(): Int = 1 +fun T.foo(): String where T : A, T : C = "" + +fun takeInt(x: Int) {} + +fun test(d: D) { + val x = d.foo() + takeInt(x) +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/arguments/overloadByReceiver.txt b/compiler/fir/resolve/testData/resolve/arguments/overloadByReceiver.txt new file mode 100644 index 00000000000..dd09a735a3a --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/arguments/overloadByReceiver.txt @@ -0,0 +1,21 @@ +FILE: overloadByReceiver.kt + public abstract interface A : R|kotlin/Any| { + } + public abstract interface B : R|A| { + } + public abstract interface C : R|kotlin/Any| { + } + public abstract interface D : R|B|, R|C| { + } + public final fun R|B|.foo(): R|kotlin/Int| { + ^foo Int(1) + } + public final fun R|T|.foo(): R|kotlin/String| { + ^foo String() + } + public final fun takeInt(x: R|kotlin/Int|): R|kotlin/Unit| { + } + public final fun test(d: R|D|): R|kotlin/Unit| { + lval x: R|kotlin/Int| = R|/d|.R|/foo|() + R|/takeInt|(R|/x|) + } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/problems.kt b/compiler/fir/resolve/testData/resolve/stdlib/problems.kt index 8a6700abd73..d4a23a10f98 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/problems.kt +++ b/compiler/fir/resolve/testData/resolve/stdlib/problems.kt @@ -21,14 +21,4 @@ class Base(val x: T) class Derived : Base(10) val xx = Derived().x + 1 -val t = throw AssertionError("") - -interface A -interface B -interface C : A -class BC : B, C -fun C.analyze() {} -inline fun T.analyze() where T : A, T : B {} -fun testAnalyze() { - BC().analyze() -} +val t = throw AssertionError("") \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/stdlib/problems.txt b/compiler/fir/resolve/testData/resolve/stdlib/problems.txt index 845f10fe57c..0500b8a8f5d 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/problems.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/problems.txt @@ -57,22 +57,3 @@ FILE: problems.kt public get(): R|kotlin/Int| public final val t: R|kotlin/Nothing| = throw R|java/lang/AssertionError.AssertionError|(String()) public get(): R|kotlin/Nothing| - public abstract interface A : R|kotlin/Any| { - } - public abstract interface B : R|kotlin/Any| { - } - public abstract interface C : R|A| { - } - public final class BC : R|B|, R|C| { - public constructor(): R|BC| { - super() - } - - } - public final fun R|C|.analyze(): R|kotlin/Unit| { - } - public final inline fun R|T|.analyze(): R|kotlin/Unit| { - } - public final fun testAnalyze(): R|kotlin/Unit| { - R|/BC.BC|().#() - } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 91f6bf46c9f..1f1d3baaf22 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -235,6 +235,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/arguments/lambda.kt"); } + @TestMetadata("overloadByReceiver.kt") + public void testOverloadByReceiver() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/arguments/overloadByReceiver.kt"); + } + @TestMetadata("overloadWithDefault.kt") public void testOverloadWithDefault() throws Exception { runTest("compiler/fir/resolve/testData/resolve/arguments/overloadWithDefault.kt"); diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableCallInsideBuilderFunction.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableCallInsideBuilderFunction.kt index 17ba9ad9d2f..25a929657b2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableCallInsideBuilderFunction.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/variableCallInsideBuilderFunction.kt @@ -2,17 +2,6 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER // !USE_EXPERIMENTAL: kotlin.Experimental -import kotlin.experimental.ExperimentalTypeInference - -interface ProducerScope { - fun yield(e: E) -} - -@UseExperimental(ExperimentalTypeInference::class) -fun produce(@BuilderInference block: ProducerScope.() -> Unit): ProducerScope = TODO() - -fun filter(e: K, predicate: (K) -> Boolean) = - produce { - predicate(e) - yield(42) - } +fun test(x: List) { + x + x +} \ No newline at end of file