diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt index bf842d0fa34..1562ed3333c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode import org.jetbrains.kotlin.resolve.descriptorUtil.varargParameterPosition import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils +import java.lang.AssertionError import java.util.* class OverloadingConflictResolver( @@ -63,7 +64,7 @@ class OverloadingConflictResolver( if (candidates.size == 1) return candidates val fixedCandidates = if (getVariableCandidates(candidates.first()) != null) { - findMaximallySpecificVariableAsFunctionCalls(candidates) ?: return candidates + findMaximallySpecificVariableAsFunctionCalls(candidates, isDebuggerContext) ?: return candidates } else { candidates @@ -137,13 +138,15 @@ class OverloadingConflictResolver( } // null means ambiguity between variables - private fun findMaximallySpecificVariableAsFunctionCalls(candidates: Set): Set? { + private fun findMaximallySpecificVariableAsFunctionCalls(candidates: Set, isDebuggerContext: Boolean): Set? { val variableCalls = candidates.mapTo(newResolvedCallSet(candidates.size)) { getVariableCandidates(it) ?: throw AssertionError("Regular call among variable-as-function calls: $it") } - val maxSpecificVariableCall = findMaximallySpecificCall(variableCalls, false, false) ?: return null + val maxSpecificVariableCalls = chooseMaximallySpecificCandidates(variableCalls, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, + isDebuggerContext = isDebuggerContext, discriminateGenerics = false) + val maxSpecificVariableCall = maxSpecificVariableCalls.singleOrNull() ?: return null return candidates.filterTo(newResolvedCallSet(2)) { getVariableCandidates(it)!!.resultingDescriptor == maxSpecificVariableCall.resultingDescriptor } diff --git a/compiler/testData/integration/ant/jvm/valWithInvoke/build.log.expected b/compiler/testData/integration/ant/jvm/valWithInvoke/build.log.expected new file mode 100644 index 00000000000..d75cf314cc2 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/valWithInvoke/build.log.expected @@ -0,0 +1,11 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [kotlinc] Compiling [[TestData]/test.kt] => [[Temp]/test.jar] + [exec] 6 + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/testData/integration/ant/jvm/valWithInvoke/build.xml b/compiler/testData/integration/ant/jvm/valWithInvoke/build.xml new file mode 100644 index 00000000000..97ddce79cb6 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/valWithInvoke/build.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/compiler/testData/integration/ant/jvm/valWithInvoke/test.kt b/compiler/testData/integration/ant/jvm/valWithInvoke/test.kt new file mode 100644 index 00000000000..17f64e3f7f4 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/valWithInvoke/test.kt @@ -0,0 +1,10 @@ +package bar + +@Suppress("REDECLARATION") +val foo: Int = 6 + +operator fun Int.invoke() = this + +fun main(args: Array) { + println(foo()) +} \ No newline at end of file diff --git a/compiler/testData/integration/ant/jvm/valWithInvoke/valInside.jar b/compiler/testData/integration/ant/jvm/valWithInvoke/valInside.jar new file mode 100644 index 00000000000..d3c7f3df4b7 Binary files /dev/null and b/compiler/testData/integration/ant/jvm/valWithInvoke/valInside.jar differ diff --git a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java index 40db17f1fd6..dc831b5305e 100644 --- a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java @@ -131,6 +131,12 @@ public class AntTaskTestGenerated extends AbstractAntTaskTest { doTest(fileName); } + @TestMetadata("valWithInvoke") + public void testValWithInvoke() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/valWithInvoke/"); + doTest(fileName); + } + @TestMetadata("verbose") public void testVerbose() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/verbose/");