From 9fa6fb213be3eb12740709e8480c42f93c7a320b Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Wed, 31 Aug 2016 19:28:58 +0300 Subject: [PATCH] Potential fix for some random errors about "cannot choose between equals invoke functions". --- .../calls/results/OverloadingConflictResolver.kt | 9 ++++++--- .../ant/jvm/valWithInvoke/build.log.expected | 11 +++++++++++ .../integration/ant/jvm/valWithInvoke/build.xml | 12 ++++++++++++ .../integration/ant/jvm/valWithInvoke/test.kt | 10 ++++++++++ .../ant/jvm/valWithInvoke/valInside.jar | Bin 0 -> 871 bytes .../kotlin/integration/AntTaskTestGenerated.java | 6 ++++++ 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/integration/ant/jvm/valWithInvoke/build.log.expected create mode 100644 compiler/testData/integration/ant/jvm/valWithInvoke/build.xml create mode 100644 compiler/testData/integration/ant/jvm/valWithInvoke/test.kt create mode 100644 compiler/testData/integration/ant/jvm/valWithInvoke/valInside.jar 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 0000000000000000000000000000000000000000..d3c7f3df4b7fb94626295d9cdaf33a39330fdee1 GIT binary patch literal 871 zcmWIWW@h1H0D*{k@}6J@l;C7wVeoYgan$wnbJPEKih&^js8oc30|?QTN&~gPmAaKC zXX|C>m*iyT#pmXyl;)%+CnO}K0dY%`nqHpXvn5BA6sJ`pyUFHnw%d4S`n}5SpZ|XT z$-1CRmhJGf$Df>^IvqJEvBqxxhffo#_kP-Xx7^AllB6)Mf& zKhcS&iiykTlhsR}*z=;x16LoNkjq!&xT5AI$GxXb^2QpAJHI3vX@uMgH3^(Q`4Pgbs#D?8z|T859s zdDpY*#s~8M{h9gRW1rhEAy?Z)S}%h<^rtLs zHA<^d`1#F$Rf2Zaf`;5vri;A46fEQ2%BXD>sq;TnTV&$ojIF$43B0d!k1$o5F-b5A zF@D+)iqT7L3+9(FGBErA;s9?(CN2i-aSBRcr~saZAjyr9NrVBB;E)pvD8V6sHjoL| xikbZIxdGJ$y+DH?sSMR>WFLXj83L>aGC?{JsV=~ql?^1%0)(G{bUYJ?2LPw$2(bVF literal 0 HcmV?d00001 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/");