From 5b33e54f77a17a7328c844e4c720b261283245a2 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Fri, 26 Apr 2019 10:19:20 +0300 Subject: [PATCH] [NI] Provide diagnostics for candidates in "allCandidates" mode This helps for completion as it use diagnostics to clip extra candidates --- .../kotlin/resolve/calls/tower/PSICallResolver.kt | 9 ++++++--- .../resolve/calls/components/KotlinCallCompleter.kt | 9 ++++++--- .../kotlin/resolve/calls/model/ResolutionAtoms.kt | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index 9f901df62bb..d15f7c8650c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -189,9 +189,12 @@ class PSICallResolver( tracingStrategy: TracingStrategy ): OverloadResolutionResults { if (result is AllCandidatesResolutionResult) { - val resolvedCalls = result.allCandidates.map { - val resultingSubstitutor = it.getSystem().asReadOnlyStorage().buildResultingSubstitutor() - kotlinToResolvedCallTransformer.transformToResolvedCall(it.resolvedCall, null, resultingSubstitutor, result.diagnostics) + val resolvedCalls = result.allCandidates.map { (candidate, diagnostics) -> + val resultingSubstitutor = candidate.getSystem().asReadOnlyStorage().buildResultingSubstitutor() + + kotlinToResolvedCallTransformer.transformToResolvedCall( + candidate.resolvedCall, null, resultingSubstitutor, diagnostics + ) } return AllCandidates(resolvedCalls) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index 66d33ea6da3..e8630db6e5f 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -58,8 +58,9 @@ class KotlinCallCompleter( expectedType: UnwrappedType?, resolutionCallbacks: KotlinResolutionCallbacks ): CallResolutionResult { - val diagnosticsHolder = KotlinDiagnosticsHolder.SimpleHolder() - for (candidate in candidates) { + val completedCandidates = candidates.map { candidate -> + val diagnosticsHolder = KotlinDiagnosticsHolder.SimpleHolder() + candidate.addExpectedTypeConstraint( candidate.returnTypeWithSmartCastInfo(resolutionCallbacks), expectedType, resolutionCallbacks ) @@ -72,8 +73,10 @@ class KotlinCallCompleter( resolutionCallbacks, collectAllCandidatesMode = true ) + + CandidateWithDiagnostics(candidate, diagnosticsHolder.getDiagnostics() + candidate.diagnosticsFromResolutionParts) } - return AllCandidatesResolutionResult(candidates) + return AllCandidatesResolutionResult(completedCandidates) } private fun KotlinResolutionCandidate.runCompletion( diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt index 3921cd5d1b4..8e55c818229 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt @@ -203,9 +203,11 @@ class ErrorCallResolutionResult( ) : SingleCallResolutionResult(resultCallAtom, diagnostics, constraintSystem) class AllCandidatesResolutionResult( - val allCandidates: Collection + val allCandidates: Collection ) : CallResolutionResult(null, emptyList(), ConstraintStorage.Empty) +data class CandidateWithDiagnostics(val candidate: KotlinResolutionCandidate, val diagnostics: List) + fun CallResolutionResult.resultCallAtom(): ResolvedCallAtom? = if (this is SingleCallResolutionResult) resultCallAtom else null