From 863b9f76035061b5ceee3517d330dd20b185d48b Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Tue, 4 Oct 2016 18:50:51 +0300 Subject: [PATCH] Minor. Change parameter type from Set to Collection. --- .../results/OverloadingConflictResolver.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 15954fdf6de..9ef863e7508 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 @@ -55,15 +55,15 @@ class OverloadingConflictResolver( // if result contains only one element -- it is maximally specific; otherwise we have ambiguity fun chooseMaximallySpecificCandidates( - candidates: Set, + candidates: Collection, checkArgumentsMode: CheckArgumentTypesMode, discriminateGenerics: Boolean, isDebuggerContext: Boolean ): Set { - if (candidates.size == 1) return candidates + candidates.setIfOneOrEmpty()?.let { return it } val fixedCandidates = if (getVariableCandidates(candidates.first()) != null) { - findMaximallySpecificVariableAsFunctionCalls(candidates, isDebuggerContext) ?: return candidates + findMaximallySpecificVariableAsFunctionCalls(candidates, isDebuggerContext) ?: return LinkedHashSet(candidates) } else { candidates @@ -93,8 +93,8 @@ class OverloadingConflictResolver( // Sometimes we should compare "copies" from sources and from binary files. // But we cannot compare return types for such copies, because it may lead us to recursive problem (see KT-11995). // Because of this we compare them without return type and choose descriptor from source if we found duplicate. - fun filterOutEquivalentCalls(candidates: Set): Set { - if (candidates.size <= 1) return candidates + fun filterOutEquivalentCalls(candidates: Collection): Set { + candidates.setIfOneOrEmpty()?.let { return it } val fromSourcesGoesFirst = candidates.sortedBy { if (isFromSources(it.resultingDescriptor)) 0 else 1 } @@ -114,6 +114,12 @@ class OverloadingConflictResolver( return result } + private fun Collection.setIfOneOrEmpty() = when(size) { + 0 -> emptySet() + 1 -> setOf(single()) + else -> null + } + private fun findMaximallySpecific( candidates: Set, checkArgumentsMode: CheckArgumentTypesMode, @@ -140,7 +146,7 @@ class OverloadingConflictResolver( } // null means ambiguity between variables - private fun findMaximallySpecificVariableAsFunctionCalls(candidates: Set, isDebuggerContext: Boolean): Set? { + private fun findMaximallySpecificVariableAsFunctionCalls(candidates: Collection, isDebuggerContext: Boolean): Set? { val variableCalls = candidates.mapTo(newResolvedCallSet(candidates.size)) { getVariableCandidates(it) ?: throw AssertionError("Regular call among variable-as-function calls: $it") }