Introduce ResolutionCandidate by commonization KotlinResolutionCandidate and CallableReferenceCandidate
Also introduced SimpleErrorResolutionCandidate
This commit is contained in:
+3
-2
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.BuilderInferenceSession
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
@@ -112,7 +113,7 @@ class InferenceSessionForExistingCandidates(
|
||||
private val resolveReceiverIndependently: Boolean,
|
||||
override val parentSession: InferenceSession?
|
||||
) : InferenceSession {
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean {
|
||||
override fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean {
|
||||
return !ErrorUtils.isError(candidate.resolvedCall.candidateDescriptor)
|
||||
}
|
||||
|
||||
@@ -135,7 +136,7 @@ class InferenceSessionForExistingCandidates(
|
||||
}
|
||||
|
||||
override fun computeCompletionMode(
|
||||
candidate: KotlinResolutionCandidate
|
||||
candidate: ResolutionCandidate
|
||||
): ConstraintSystemCompletionMode? = null
|
||||
|
||||
override fun resolveReceiverIndependently(): Boolean = resolveReceiverIndependently
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.util.shouldBeSubstituteWithStubTypes
|
||||
import org.jetbrains.kotlin.resolve.calls.util.toOldSubstitution
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||
@@ -80,7 +81,7 @@ class BuilderInferenceSession(
|
||||
|
||||
override val parentSession = topLevelCallContext.inferenceSession
|
||||
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean {
|
||||
override fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean {
|
||||
val system = candidate.getSystem() as NewConstraintSystemImpl
|
||||
|
||||
if (system.hasContradiction) return true
|
||||
|
||||
+1
-1
@@ -309,7 +309,7 @@ class KotlinResolutionCallbacksImpl(
|
||||
return convertSignedConstantToUnsigned(argumentExpression)
|
||||
}
|
||||
|
||||
override fun recordInlinabilityOfLambda(atom: Set<Map.Entry<KotlinResolutionCandidate, ResolvedLambdaAtom>>) {
|
||||
override fun recordInlinabilityOfLambda(atom: Set<Map.Entry<SimpleResolutionCandidate, ResolvedLambdaAtom>>) {
|
||||
val call = atom.first().value.atom.psiCallArgument.valueArgument as? KtLambdaArgument ?: return
|
||||
val literal = call.getLambdaExpression()?.functionLiteral ?: return
|
||||
val isLambdaInline = atom.all { (candidate, atom) ->
|
||||
|
||||
+3
-2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve.calls.tower
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
|
||||
@@ -40,7 +41,7 @@ abstract class ManyCandidatesResolver<D : CallableDescriptor>(
|
||||
// do nothing
|
||||
}
|
||||
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean {
|
||||
override fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -168,7 +169,7 @@ abstract class ManyCandidatesResolver<D : CallableDescriptor>(
|
||||
return allCandidates
|
||||
}
|
||||
|
||||
override fun computeCompletionMode(candidate: KotlinResolutionCandidate) = null
|
||||
override fun computeCompletionMode(candidate: ResolutionCandidate) = null
|
||||
|
||||
override fun resolveReceiverIndependently(): Boolean = false
|
||||
|
||||
|
||||
+4
@@ -487,6 +487,10 @@ class NewResolutionOldInference(
|
||||
}
|
||||
}
|
||||
|
||||
override fun createErrorCandidate(): MyCandidate {
|
||||
throw IllegalStateException("Not supported creating error candidate for the old type inference candidate factory")
|
||||
}
|
||||
|
||||
private fun createDiagnosticsForCandidate(
|
||||
towerCandidate: CandidateWithBoundDispatchReceiver,
|
||||
candidateCall: ResolvedCallImpl<CallableDescriptor>
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.util.*
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
|
||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.buildResultingSubstitutor
|
||||
@@ -327,12 +328,12 @@ class PSICallResolver(
|
||||
private fun CallResolutionResult.isEmpty(): Boolean =
|
||||
diagnostics.firstIsInstanceOrNull<NoneCandidatesCallDiagnostic>() != null
|
||||
|
||||
private fun Collection<KotlinResolutionCandidate>.areAllFailed() =
|
||||
private fun Collection<ResolutionCandidate>.areAllFailed() =
|
||||
all {
|
||||
!it.resultingApplicability.isSuccess
|
||||
}
|
||||
|
||||
private fun Collection<KotlinResolutionCandidate>.areAllFailedWithInapplicableWrongReceiver() =
|
||||
private fun Collection<ResolutionCandidate>.areAllFailedWithInapplicableWrongReceiver() =
|
||||
all {
|
||||
it.resultingApplicability == CandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
|
||||
}
|
||||
@@ -458,18 +459,18 @@ class PSICallResolver(
|
||||
val context: BasicCallResolutionContext,
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
val kotlinCall: PSIKotlinCallImpl
|
||||
) : CandidateFactoryProviderForInvoke<KotlinResolutionCandidate> {
|
||||
) : CandidateFactoryProviderForInvoke<ResolutionCandidate> {
|
||||
|
||||
init {
|
||||
assert(kotlinCall.dispatchReceiverForInvokeExtension == null) { kotlinCall }
|
||||
}
|
||||
|
||||
override fun transformCandidate(
|
||||
variable: KotlinResolutionCandidate,
|
||||
invoke: KotlinResolutionCandidate
|
||||
variable: ResolutionCandidate,
|
||||
invoke: ResolutionCandidate
|
||||
) = invoke
|
||||
|
||||
override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<KotlinResolutionCandidate> {
|
||||
override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory<ResolutionCandidate> {
|
||||
val explicitReceiver = if (stripExplicitReceiver) null else kotlinCall.explicitReceiver
|
||||
val variableCall = PSIKotlinCallForVariable(kotlinCall, explicitReceiver, kotlinCall.name)
|
||||
return SimpleCandidateFactory(
|
||||
@@ -477,8 +478,8 @@ class PSICallResolver(
|
||||
)
|
||||
}
|
||||
|
||||
override fun factoryForInvoke(variable: KotlinResolutionCandidate, useExplicitReceiver: Boolean):
|
||||
Pair<ReceiverValueWithSmartCastInfo, CandidateFactory<KotlinResolutionCandidate>>? {
|
||||
override fun factoryForInvoke(variable: ResolutionCandidate, useExplicitReceiver: Boolean):
|
||||
Pair<ReceiverValueWithSmartCastInfo, CandidateFactory<ResolutionCandidate>>? {
|
||||
if (isRecursiveVariableResolution(variable)) return null
|
||||
|
||||
assert(variable.isSuccessful) {
|
||||
@@ -500,13 +501,13 @@ class PSICallResolver(
|
||||
}
|
||||
|
||||
// todo: create special check that there is no invoke on variable
|
||||
private fun isRecursiveVariableResolution(variable: KotlinResolutionCandidate): Boolean {
|
||||
private fun isRecursiveVariableResolution(variable: ResolutionCandidate): Boolean {
|
||||
val variableType = variable.resolvedCall.candidateDescriptor.returnType
|
||||
return variableType is DeferredType && variableType.isComputing
|
||||
}
|
||||
|
||||
// todo: review
|
||||
private fun createReceiverCallArgument(variable: KotlinResolutionCandidate): SimpleKotlinCallArgument {
|
||||
private fun createReceiverCallArgument(variable: ResolutionCandidate): SimpleKotlinCallArgument {
|
||||
variable.forceResolution()
|
||||
val variableReceiver = createReceiverValueWithSmartCastInfo(variable)
|
||||
if (variableReceiver.hasTypesFromSmartCasts()) {
|
||||
@@ -528,7 +529,7 @@ class PSICallResolver(
|
||||
}
|
||||
|
||||
// todo: decrease hacks count
|
||||
private fun createReceiverValueWithSmartCastInfo(variable: KotlinResolutionCandidate): ReceiverValueWithSmartCastInfo {
|
||||
private fun createReceiverValueWithSmartCastInfo(variable: ResolutionCandidate): ReceiverValueWithSmartCastInfo {
|
||||
val callForVariable = variable.resolvedCall.atom as PSIKotlinCallForVariable
|
||||
val calleeExpression = callForVariable.baseCall.psiCall.calleeExpression as? KtReferenceExpression
|
||||
?: error("Unexpected call : ${callForVariable.baseCall.psiCall}")
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.Call
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
@@ -93,7 +94,7 @@ class PSIKotlinCallForVariable(
|
||||
|
||||
class PSIKotlinCallForInvoke(
|
||||
val baseCall: PSIKotlinCallImpl,
|
||||
val variableCall: KotlinResolutionCandidate,
|
||||
val variableCall: ResolutionCandidate,
|
||||
override val explicitReceiver: ReceiverKotlinCallArgument,
|
||||
override val dispatchReceiverForInvokeExtension: SimpleKotlinCallArgument?
|
||||
) : PSIKotlinCall() {
|
||||
|
||||
+3
-5
@@ -21,10 +21,8 @@ import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
||||
import org.jetbrains.kotlin.resolve.calls.util.toOldSubstitution
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.calls.commonSuperType
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceAdaptation
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.SuspendConversionStrategy
|
||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.BuilderInferenceSession
|
||||
@@ -401,7 +399,7 @@ class ResolvedAtomCompleter(
|
||||
}
|
||||
|
||||
private fun extractCallableReferenceResultTypeInfoFromDescriptor(
|
||||
callableCandidate: CallableReferenceCandidate,
|
||||
callableCandidate: CallableReferenceResolutionCandidate,
|
||||
recordedDescriptor: CallableDescriptor
|
||||
): CallableReferenceResultTypeInfo {
|
||||
val dispatchReceiver = recordedDescriptor.dispatchReceiverParameter?.value
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinCallCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.components.NewOverloadingConflictResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
@@ -32,7 +33,7 @@ class KotlinCallResolver(
|
||||
kotlinCall: KotlinCall,
|
||||
expectedType: UnwrappedType?,
|
||||
collectAllCandidates: Boolean,
|
||||
createFactoryProviderForInvoke: () -> CandidateFactoryProviderForInvoke<KotlinResolutionCandidate>
|
||||
createFactoryProviderForInvoke: () -> CandidateFactoryProviderForInvoke<ResolutionCandidate>
|
||||
): CallResolutionResult {
|
||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||
|
||||
@@ -120,7 +121,7 @@ class KotlinCallResolver(
|
||||
candidateFactory: SimpleCandidateFactory,
|
||||
resolutionCallbacks: KotlinResolutionCallbacks,
|
||||
expectedType: UnwrappedType?,
|
||||
candidates: Collection<KotlinResolutionCandidate>
|
||||
candidates: Collection<ResolutionCandidate>
|
||||
): CallResolutionResult {
|
||||
var refinedCandidates = candidates
|
||||
if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.RefinedSamAdaptersPriority)) {
|
||||
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.components
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.model.CompatibilityWarning
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.Candidate
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.getResultApplicability
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
/**
|
||||
* Suppose we have class A with staticM, memberM, memberExtM.
|
||||
* For A::staticM both receivers will be null
|
||||
* For A::memberM dispatchReceiver = UnboundReceiver, extensionReceiver = null
|
||||
* For a::memberExtM dispatchReceiver = ExplicitValueReceiver, extensionReceiver = ExplicitValueReceiver
|
||||
*
|
||||
* For class B with companion object B::companionM dispatchReceiver = BoundValueReference
|
||||
*/
|
||||
class CallableReferenceCandidate(
|
||||
val candidate: CallableDescriptor,
|
||||
val dispatchReceiver: CallableReceiver?,
|
||||
val extensionReceiver: CallableReceiver?,
|
||||
val explicitReceiverKind: ExplicitReceiverKind,
|
||||
val reflectionCandidateType: UnwrappedType,
|
||||
val callableReferenceAdaptation: CallableReferenceAdaptation?,
|
||||
initialDiagnostics: List<KotlinCallDiagnostic>
|
||||
) : Candidate {
|
||||
private val mutableDiagnostics = initialDiagnostics.toMutableList()
|
||||
val diagnostics: List<KotlinCallDiagnostic> = mutableDiagnostics
|
||||
|
||||
override val resultingApplicability = getResultApplicability(diagnostics)
|
||||
|
||||
override fun addCompatibilityWarning(other: Candidate) {
|
||||
if (this !== other && other is CallableReferenceCandidate) {
|
||||
mutableDiagnostics.add(CompatibilityWarning(other.candidate))
|
||||
}
|
||||
}
|
||||
|
||||
override val isSuccessful get() = resultingApplicability.isSuccess
|
||||
|
||||
var freshSubstitutor: FreshVariableNewTypeSubstitutor? = null
|
||||
internal set
|
||||
|
||||
val numDefaults get() = callableReferenceAdaptation?.defaults ?: 0
|
||||
}
|
||||
+2
-2
@@ -24,7 +24,7 @@ typealias CsCompleterContext = ConstraintSystemCompletionContext
|
||||
class CompletionModeCalculator {
|
||||
companion object {
|
||||
fun computeCompletionMode(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
expectedType: UnwrappedType?,
|
||||
returnType: UnwrappedType?,
|
||||
trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle,
|
||||
@@ -53,7 +53,7 @@ class CompletionModeCalculator {
|
||||
}
|
||||
|
||||
private class CalculatorForNestedCall(
|
||||
private val candidate: KotlinResolutionCandidate,
|
||||
private val candidate: ResolutionCandidate,
|
||||
private val returnType: UnwrappedType?,
|
||||
private val csCompleterContext: CsCompleterContext,
|
||||
private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle,
|
||||
|
||||
+1
-1
@@ -89,5 +89,5 @@ interface KotlinResolutionCallbacks {
|
||||
|
||||
fun convertSignedConstantToUnsigned(argument: KotlinCallArgument): IntegerValueTypeConstant?
|
||||
|
||||
fun recordInlinabilityOfLambda(atom: Set<Map.Entry<KotlinResolutionCandidate, ResolvedLambdaAtom>>)
|
||||
fun recordInlinabilityOfLambda(atom: Set<Map.Entry<SimpleResolutionCandidate, ResolvedLambdaAtom>>)
|
||||
}
|
||||
|
||||
+5
-4
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.components
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
@@ -18,7 +19,7 @@ interface InferenceSession {
|
||||
val default = object : InferenceSession {
|
||||
override val parentSession: InferenceSession? = null
|
||||
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean = true
|
||||
override fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean = true
|
||||
override fun addPartialCallInfo(callInfo: PartialCallInfo) {}
|
||||
override fun addErrorCallInfo(callInfo: ErrorCallInfo) {}
|
||||
override fun addCompletedCallInfo(callInfo: CompletedCallInfo) {}
|
||||
@@ -36,14 +37,14 @@ interface InferenceSession {
|
||||
override fun callCompleted(resolvedAtom: ResolvedAtom): Boolean = false
|
||||
override fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom) = true
|
||||
override fun computeCompletionMode(
|
||||
candidate: KotlinResolutionCandidate
|
||||
candidate: ResolutionCandidate
|
||||
): ConstraintSystemCompletionMode? = null
|
||||
|
||||
override fun resolveReceiverIndependently(): Boolean = false
|
||||
}
|
||||
}
|
||||
|
||||
fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean
|
||||
fun shouldRunCompletion(candidate: ResolutionCandidate): Boolean
|
||||
fun addPartialCallInfo(callInfo: PartialCallInfo)
|
||||
fun addCompletedCallInfo(callInfo: CompletedCallInfo)
|
||||
fun addErrorCallInfo(callInfo: ErrorCallInfo)
|
||||
@@ -60,7 +61,7 @@ interface InferenceSession {
|
||||
fun writeOnlyStubs(callInfo: SingleCallResolutionResult): Boolean
|
||||
fun callCompleted(resolvedAtom: ResolvedAtom): Boolean
|
||||
fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom): Boolean
|
||||
fun computeCompletionMode(candidate: KotlinResolutionCandidate): ConstraintSystemCompletionMode?
|
||||
fun computeCompletionMode(candidate: ResolutionCandidate): ConstraintSystemCompletionMode?
|
||||
fun resolveReceiverIndependently(): Boolean
|
||||
}
|
||||
|
||||
|
||||
+21
-18
@@ -9,6 +9,9 @@ import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.SimpleResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.addEqualityConstraintIfCompatible
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
@@ -31,8 +34,8 @@ class KotlinCallCompleter(
|
||||
) {
|
||||
|
||||
fun runCompletion(
|
||||
factory: SimpleCandidateFactory,
|
||||
candidates: Collection<KotlinResolutionCandidate>,
|
||||
factory: CandidateFactory<ResolutionCandidate>,
|
||||
candidates: Collection<ResolutionCandidate>,
|
||||
expectedType: UnwrappedType?,
|
||||
resolutionCallbacks: KotlinResolutionCallbacks
|
||||
): CallResolutionResult {
|
||||
@@ -75,9 +78,9 @@ class KotlinCallCompleter(
|
||||
}
|
||||
|
||||
fun chooseCandidateRegardingOverloadResolutionByLambdaReturnType(
|
||||
candidates: Set<KotlinResolutionCandidate>,
|
||||
candidates: Set<SimpleResolutionCandidate>,
|
||||
resolutionCallbacks: KotlinResolutionCallbacks
|
||||
): Set<KotlinResolutionCandidate> {
|
||||
): Set<SimpleResolutionCandidate> {
|
||||
val lambdas = candidates.flatMap { candidate ->
|
||||
candidate.getSubResolvedAtoms()
|
||||
.filter { it is ResolvedLambdaAtom && !it.analyzed }
|
||||
@@ -130,8 +133,8 @@ class KotlinCallCompleter(
|
||||
)
|
||||
}
|
||||
|
||||
val errorCandidates = mutableSetOf<KotlinResolutionCandidate>()
|
||||
val successfulCandidates = mutableSetOf<KotlinResolutionCandidate>()
|
||||
val errorCandidates = mutableSetOf<SimpleResolutionCandidate>()
|
||||
val successfulCandidates = mutableSetOf<SimpleResolutionCandidate>()
|
||||
|
||||
for (candidate in candidates) {
|
||||
if (candidate.isSuccessful) {
|
||||
@@ -146,7 +149,7 @@ class KotlinCallCompleter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.getInputTypesOfLambdaAtom(atom: ResolvedLambdaAtom): List<UnwrappedType> {
|
||||
private fun SimpleResolutionCandidate.getInputTypesOfLambdaAtom(atom: ResolvedLambdaAtom): List<UnwrappedType> {
|
||||
val result = mutableListOf<UnwrappedType>()
|
||||
val substitutor = csBuilder.buildCurrentSubstitutor()
|
||||
val ctx = getSystem().asConstraintSystemCompleterContext()
|
||||
@@ -157,7 +160,7 @@ class KotlinCallCompleter(
|
||||
}
|
||||
|
||||
|
||||
private fun KotlinResolutionCandidate.checkSamWithVararg(diagnosticHolder: KotlinDiagnosticsHolder.SimpleHolder) {
|
||||
private fun ResolutionCandidate.checkSamWithVararg(diagnosticHolder: KotlinDiagnosticsHolder.SimpleHolder) {
|
||||
val samConversionPerArgumentWithWarningsForVarargAfterSam =
|
||||
callComponents.languageVersionSettings.supportsFeature(LanguageFeature.SamConversionPerArgument) &&
|
||||
!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ProhibitVarargAsArrayAfterSamArgument)
|
||||
@@ -174,7 +177,7 @@ class KotlinCallCompleter(
|
||||
}
|
||||
|
||||
fun createAllCandidatesResult(
|
||||
candidates: Collection<KotlinResolutionCandidate>,
|
||||
candidates: Collection<ResolutionCandidate>,
|
||||
expectedType: UnwrappedType?,
|
||||
resolutionCallbacks: KotlinResolutionCallbacks
|
||||
): CallResolutionResult {
|
||||
@@ -199,7 +202,7 @@ class KotlinCallCompleter(
|
||||
return AllCandidatesResolutionResult(completedCandidates)
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.runCompletion(
|
||||
private fun ResolutionCandidate.runCompletion(
|
||||
completionMode: ConstraintSystemCompletionMode,
|
||||
diagnosticHolder: KotlinDiagnosticsHolder,
|
||||
resolutionCallbacks: KotlinResolutionCallbacks,
|
||||
@@ -240,10 +243,10 @@ class KotlinCallCompleter(
|
||||
}
|
||||
|
||||
private fun prepareCandidateForCompletion(
|
||||
factory: SimpleCandidateFactory,
|
||||
candidates: Collection<KotlinResolutionCandidate>,
|
||||
factory: CandidateFactory<ResolutionCandidate>,
|
||||
candidates: Collection<ResolutionCandidate>,
|
||||
resolutionCallbacks: KotlinResolutionCallbacks
|
||||
): KotlinResolutionCandidate {
|
||||
): ResolutionCandidate {
|
||||
val candidate = candidates.singleOrNull()
|
||||
|
||||
// this is needed at least for non-local return checker, because when we analyze lambda we should already bind descriptor for outer call
|
||||
@@ -260,12 +263,12 @@ class KotlinCallCompleter(
|
||||
return candidate ?: factory.createErrorCandidate().forceResolution()
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.substitutedReturnType(): UnwrappedType? {
|
||||
private fun ResolutionCandidate.substitutedReturnType(): UnwrappedType? {
|
||||
val returnType = resolvedCall.candidateDescriptor.returnType?.unwrap() ?: return null
|
||||
return resolvedCall.freshVariablesSubstitutor.safeSubstitute(returnType)
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.addExpectedTypeConstraint(
|
||||
private fun ResolutionCandidate.addExpectedTypeConstraint(
|
||||
returnType: UnwrappedType?,
|
||||
expectedType: UnwrappedType?
|
||||
) {
|
||||
@@ -294,7 +297,7 @@ class KotlinCallCompleter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.addExpectedTypeFromCastConstraint(
|
||||
private fun ResolutionCandidate.addExpectedTypeFromCastConstraint(
|
||||
returnType: UnwrappedType?,
|
||||
resolutionCallbacks: KotlinResolutionCallbacks
|
||||
) {
|
||||
@@ -304,7 +307,7 @@ class KotlinCallCompleter(
|
||||
csBuilder.addSubtypeConstraint(returnType, expectedType, ExpectedTypeConstraintPositionImpl(resolvedCall.atom))
|
||||
}
|
||||
|
||||
fun KotlinResolutionCandidate.asCallResolutionResult(
|
||||
fun ResolutionCandidate.asCallResolutionResult(
|
||||
type: ConstraintSystemCompletionMode,
|
||||
diagnosticsHolder: KotlinDiagnosticsHolder.SimpleHolder,
|
||||
forwardToInferenceSession: Boolean = false
|
||||
@@ -324,6 +327,6 @@ class KotlinCallCompleter(
|
||||
}
|
||||
}
|
||||
|
||||
internal fun KotlinResolutionCandidate.isErrorCandidate(): Boolean {
|
||||
internal fun ResolutionCandidate.isErrorCandidate(): Boolean {
|
||||
return ErrorUtils.isError(resolvedCall.candidateDescriptor) || hasContradiction
|
||||
}
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.results.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -37,7 +37,7 @@ class NewOverloadingConflictResolver(
|
||||
statelessCallbacks: KotlinResolutionStatelessCallbacks,
|
||||
constraintInjector: ConstraintInjector,
|
||||
kotlinTypeRefiner: KotlinTypeRefiner,
|
||||
) : OverloadingConflictResolver<KotlinResolutionCandidate>(
|
||||
) : OverloadingConflictResolver<ResolutionCandidate>(
|
||||
builtIns,
|
||||
module,
|
||||
specificityComparator,
|
||||
@@ -56,7 +56,7 @@ class NewOverloadingConflictResolver(
|
||||
) {
|
||||
|
||||
companion object {
|
||||
private fun createFlatSignature(candidate: KotlinResolutionCandidate): FlatSignature<KotlinResolutionCandidate> {
|
||||
private fun createFlatSignature(candidate: ResolutionCandidate): FlatSignature<ResolutionCandidate> {
|
||||
|
||||
val resolvedCall = candidate.resolvedCall
|
||||
val originalDescriptor = resolvedCall.candidateDescriptor.original
|
||||
|
||||
+30
-28
@@ -11,6 +11,8 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper.TypeArgumentsMapping.NoExplicitArguments
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.*
|
||||
@@ -35,7 +37,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.compactIfPossible
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal object CheckVisibility : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
val containingDescriptor = scopeTower.lexicalScope.ownerDescriptor
|
||||
val dispatchReceiverArgument = resolvedCall.dispatchReceiverArgument
|
||||
|
||||
@@ -62,7 +64,7 @@ internal object CheckVisibility : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object MapTypeArguments : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
resolvedCall.typeArgumentMappingByOriginal =
|
||||
callComponents.typeArgumentsToParametersMapper.mapTypeArguments(kotlinCall, candidateDescriptor.original).also {
|
||||
it.diagnostics.forEach(this@process::addDiagnostic)
|
||||
@@ -71,7 +73,7 @@ internal object MapTypeArguments : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object NoTypeArguments : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
assert(kotlinCall.typeArguments.isEmpty()) {
|
||||
"Variable call cannot has explicit type arguments: ${kotlinCall.typeArguments}. Call: $kotlinCall"
|
||||
}
|
||||
@@ -80,7 +82,7 @@ internal object NoTypeArguments : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object MapArguments : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
val mapping = callComponents.argumentsToParametersMapper.mapArguments(kotlinCall, candidateDescriptor)
|
||||
mapping.diagnostics.forEach(this::addDiagnostic)
|
||||
|
||||
@@ -89,7 +91,7 @@ internal object MapArguments : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object ArgumentsToCandidateParameterDescriptor : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
val map = hashMapOf<KotlinCallArgument, ValueParameterDescriptor>()
|
||||
for ((originalValueParameter, resolvedCallArgument) in resolvedCall.argumentMappingByOriginal) {
|
||||
val valueParameter = candidateDescriptor.valueParameters.getOrNull(originalValueParameter.index) ?: continue
|
||||
@@ -102,7 +104,7 @@ internal object ArgumentsToCandidateParameterDescriptor : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object NoArguments : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
assert(kotlinCall.argumentsInParenthesis.isEmpty()) {
|
||||
"Variable call cannot has arguments: ${kotlinCall.argumentsInParenthesis}. Call: $kotlinCall"
|
||||
}
|
||||
@@ -116,7 +118,7 @@ internal object NoArguments : ResolutionPart() {
|
||||
|
||||
|
||||
internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
val toFreshVariables =
|
||||
if (candidateDescriptor.typeParameters.isEmpty())
|
||||
FreshVariableNewTypeSubstitutor.Empty
|
||||
@@ -272,7 +274,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
for ((argument, parameter) in resolvedCall.argumentToCandidateParameter) {
|
||||
if (!callComponents.statelessCallbacks.isBuilderInferenceCall(argument, parameter)) continue
|
||||
val receiverType = parameter.type.getReceiverTypeFromFunctionType() ?: continue
|
||||
@@ -299,7 +301,7 @@ internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object CompatibilityOfTypeVariableAsIntersectionTypePart : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
for ((_, variableWithConstraints) in csBuilder.currentStorage().notFixedTypeVariables) {
|
||||
val constraints = variableWithConstraints.constraints.filter { csBuilder.isProperType(it.type) }
|
||||
|
||||
@@ -317,7 +319,7 @@ internal object CompatibilityOfTypeVariableAsIntersectionTypePart : ResolutionPa
|
||||
}
|
||||
|
||||
internal object CompatibilityOfPartiallyApplicableSamConversion : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
if (resolvedCall.argumentsWithConversion.isEmpty()) return
|
||||
if (resolvedCall.argumentsWithConversion.size == candidateDescriptor.valueParameters.size) return
|
||||
|
||||
@@ -339,14 +341,14 @@ internal object CompatibilityOfPartiallyApplicableSamConversion : ResolutionPart
|
||||
}
|
||||
|
||||
internal object CheckExplicitReceiverKindConsistency : ResolutionPart() {
|
||||
private fun KotlinResolutionCandidate.hasError(): Nothing =
|
||||
private fun ResolutionCandidate.hasError(): Nothing =
|
||||
error(
|
||||
"Inconsistent call: $kotlinCall. \n" +
|
||||
"Candidate: $candidateDescriptor, explicitReceiverKind: ${resolvedCall.explicitReceiverKind}.\n" +
|
||||
"Explicit receiver: ${kotlinCall.explicitReceiver}, dispatchReceiverForInvokeExtension: ${kotlinCall.dispatchReceiverForInvokeExtension}"
|
||||
)
|
||||
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
when (resolvedCall.explicitReceiverKind) {
|
||||
NO_EXPLICIT_RECEIVER -> if (kotlinCall.explicitReceiver is SimpleKotlinCallArgument || kotlinCall.dispatchReceiverForInvokeExtension != null) hasError()
|
||||
DISPATCH_RECEIVER, EXTENSION_RECEIVER ->
|
||||
@@ -483,7 +485,7 @@ internal object CollectionTypeVariableUsagesInfo : ResolutionPart() {
|
||||
freshTypeConstructor.isContainedInInvariantOrContravariantPositions = true
|
||||
}
|
||||
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
for (variable in resolvedCall.freshVariablesSubstitutor.freshVariables) {
|
||||
if (resolvedCall.candidateDescriptor is ClassConstructorDescriptor) {
|
||||
val typeParameters = resolvedCall.candidateDescriptor.containingDeclaration.declaredTypeParameters
|
||||
@@ -498,7 +500,7 @@ internal object CollectionTypeVariableUsagesInfo : ResolutionPart() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.resolveKotlinArgument(
|
||||
private fun ResolutionCandidate.resolveKotlinArgument(
|
||||
argument: KotlinCallArgument,
|
||||
candidateParameter: ParameterDescriptor?,
|
||||
receiverInfo: ReceiverInfo
|
||||
@@ -598,7 +600,7 @@ private fun KotlinResolutionCandidate.resolveKotlinArgument(
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.shouldRunConversionForConstants(expectedType: UnwrappedType): Boolean {
|
||||
private fun ResolutionCandidate.shouldRunConversionForConstants(expectedType: UnwrappedType): Boolean {
|
||||
if (UnsignedTypes.isUnsignedType(expectedType)) return true
|
||||
if (csBuilder.isTypeVariable(expectedType)) {
|
||||
val variableWithConstraints = csBuilder.currentStorage().notFixedTypeVariables[expectedType.constructor] ?: return false
|
||||
@@ -617,7 +619,7 @@ internal enum class ImplicitInvokeCheckStatus {
|
||||
NO_INVOKE, INVOKE_ON_NOT_NULL_VARIABLE, UNSAFE_INVOKE_REPORTED
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.checkUnsafeImplicitInvokeAfterSafeCall(argument: SimpleKotlinCallArgument): ImplicitInvokeCheckStatus {
|
||||
private fun ResolutionCandidate.checkUnsafeImplicitInvokeAfterSafeCall(argument: SimpleKotlinCallArgument): ImplicitInvokeCheckStatus {
|
||||
val variableForInvoke = variableCandidateIfInvoke ?: return ImplicitInvokeCheckStatus.NO_INVOKE
|
||||
|
||||
val receiverArgument = with(variableForInvoke.resolvedCall) {
|
||||
@@ -637,13 +639,13 @@ private fun KotlinResolutionCandidate.checkUnsafeImplicitInvokeAfterSafeCall(arg
|
||||
return ImplicitInvokeCheckStatus.INVOKE_ON_NOT_NULL_VARIABLE
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.prepareExpectedType(expectedType: UnwrappedType): UnwrappedType {
|
||||
private fun ResolutionCandidate.prepareExpectedType(expectedType: UnwrappedType): UnwrappedType {
|
||||
val resultType = resolvedCall.freshVariablesSubstitutor.safeSubstitute(expectedType)
|
||||
return resolvedCall.knownParametersSubstitutor.safeSubstitute(resultType)
|
||||
}
|
||||
|
||||
internal object CheckReceivers : ResolutionPart() {
|
||||
private fun KotlinResolutionCandidate.checkReceiver(
|
||||
private fun ResolutionCandidate.checkReceiver(
|
||||
receiverArgument: SimpleKotlinCallArgument?,
|
||||
receiverParameter: ReceiverParameterDescriptor?,
|
||||
shouldCheckImplicitInvoke: Boolean,
|
||||
@@ -666,7 +668,7 @@ internal object CheckReceivers : ResolutionPart() {
|
||||
resolveKotlinArgument(receiverArgument, receiverParameter, receiverInfo)
|
||||
}
|
||||
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
if (workIndex == 0) {
|
||||
checkReceiver(
|
||||
resolvedCall.dispatchReceiverArgument,
|
||||
@@ -682,20 +684,20 @@ internal object CheckReceivers : ResolutionPart() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun KotlinResolutionCandidate.workCount() = 2
|
||||
override fun ResolutionCandidate.workCount() = 2
|
||||
}
|
||||
|
||||
internal object CheckArgumentsInParenthesis : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
val argument = kotlinCall.argumentsInParenthesis[workIndex]
|
||||
resolveKotlinArgument(argument, resolvedCall.argumentToCandidateParameter[argument], ReceiverInfo.notReceiver)
|
||||
}
|
||||
|
||||
override fun KotlinResolutionCandidate.workCount() = kotlinCall.argumentsInParenthesis.size
|
||||
override fun ResolutionCandidate.workCount() = kotlinCall.argumentsInParenthesis.size
|
||||
}
|
||||
|
||||
internal object CheckExternalArgument : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
val argument = kotlinCall.externalArgument ?: return
|
||||
|
||||
resolveKotlinArgument(argument, resolvedCall.argumentToCandidateParameter[argument], ReceiverInfo.notReceiver)
|
||||
@@ -703,7 +705,7 @@ internal object CheckExternalArgument : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object EagerResolveOfCallableReferences : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
getSubResolvedAtoms()
|
||||
.filterIsInstance<EagerCallableReferenceAtom>()
|
||||
.forEach {
|
||||
@@ -713,7 +715,7 @@ internal object EagerResolveOfCallableReferences : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object CheckInfixResolutionPart : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
val candidateDescriptor = resolvedCall.candidateDescriptor
|
||||
if (candidateDescriptor !is FunctionDescriptor) return
|
||||
if (!candidateDescriptor.isInfix && callComponents.statelessCallbacks.isInfixCall(kotlinCall)) {
|
||||
@@ -723,7 +725,7 @@ internal object CheckInfixResolutionPart : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object CheckOperatorResolutionPart : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
val candidateDescriptor = resolvedCall.candidateDescriptor
|
||||
if (candidateDescriptor !is FunctionDescriptor) return
|
||||
if (!candidateDescriptor.isOperator && callComponents.statelessCallbacks.isOperatorCall(kotlinCall)) {
|
||||
@@ -733,7 +735,7 @@ internal object CheckOperatorResolutionPart : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object CheckSuperExpressionCallPart : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
val candidateDescriptor = resolvedCall.candidateDescriptor
|
||||
|
||||
if (callComponents.statelessCallbacks.isSuperExpression(resolvedCall.dispatchReceiverArgument)) {
|
||||
@@ -750,7 +752,7 @@ internal object CheckSuperExpressionCallPart : ResolutionPart() {
|
||||
}
|
||||
|
||||
internal object ErrorDescriptorResolutionPart : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
override fun ResolutionCandidate.process(workIndex: Int) {
|
||||
assert(ErrorUtils.isError(candidateDescriptor)) {
|
||||
"Should be error descriptor: $candidateDescriptor"
|
||||
}
|
||||
|
||||
+5
-4
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.incremental.record
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.sam.SAM_LOOKUP_NAME
|
||||
import org.jetbrains.kotlin.resolve.sam.getFunctionTypeForPossibleSamType
|
||||
@@ -19,7 +20,7 @@ import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||
|
||||
object SamTypeConversions : ParameterTypeConversion {
|
||||
override fun conversionDefinitelyNotNeeded(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
expectedParameterType: UnwrappedType
|
||||
): Boolean {
|
||||
@@ -72,7 +73,7 @@ object SamTypeConversions : ParameterTypeConversion {
|
||||
}
|
||||
|
||||
override fun convertParameterType(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
parameter: ParameterDescriptor,
|
||||
expectedParameterType: UnwrappedType
|
||||
@@ -118,7 +119,7 @@ object SamTypeConversions : ParameterTypeConversion {
|
||||
return convertedTypeByCandidate
|
||||
}
|
||||
|
||||
private fun needCompatibilityResolveForSAM(candidate: KotlinResolutionCandidate, typeToConvert: UnwrappedType): Boolean {
|
||||
private fun needCompatibilityResolveForSAM(candidate: ResolutionCandidate, typeToConvert: UnwrappedType): Boolean {
|
||||
// fun interfaces is a new feature with a new modifier, so no compatibility resolve is needed
|
||||
val descriptor = typeToConvert.constructor.declarationDescriptor
|
||||
if (descriptor is ClassDescriptor && descriptor.isFun) return false
|
||||
@@ -128,7 +129,7 @@ object SamTypeConversions : ParameterTypeConversion {
|
||||
}
|
||||
|
||||
fun isJavaParameterCanBeConverted(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
expectedParameterType: UnwrappedType
|
||||
): Boolean {
|
||||
val callComponents = candidate.callComponents
|
||||
|
||||
+3
-3
@@ -8,13 +8,13 @@ package org.jetbrains.kotlin.resolve.calls.components
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
object SuspendTypeConversions : ParameterTypeConversion {
|
||||
override fun conversionDefinitelyNotNeeded(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
expectedParameterType: UnwrappedType
|
||||
): Boolean {
|
||||
@@ -35,7 +35,7 @@ object SuspendTypeConversions : ParameterTypeConversion {
|
||||
argument is SimpleKotlinCallArgument && argument.receiver.stableType.isFunctionTypeOrSubtype
|
||||
|
||||
override fun convertParameterType(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
parameter: ParameterDescriptor,
|
||||
expectedParameterType: UnwrappedType
|
||||
|
||||
+3
-2
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.components
|
||||
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
|
||||
@@ -20,7 +21,7 @@ import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
|
||||
object UnitTypeConversions : ParameterTypeConversion {
|
||||
override fun conversionDefinitelyNotNeeded(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
expectedParameterType: UnwrappedType
|
||||
): Boolean {
|
||||
@@ -67,7 +68,7 @@ object UnitTypeConversions : ParameterTypeConversion {
|
||||
}
|
||||
|
||||
override fun convertParameterType(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
parameter: ParameterDescriptor,
|
||||
expectedParameterType: UnwrappedType
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.components.candidate
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReceiver
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceAdaptation
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
/**
|
||||
* Suppose we have class A with staticM, memberM, memberExtM.
|
||||
* For A::staticM both receivers will be null
|
||||
* For A::memberM dispatchReceiver = UnboundReceiver, extensionReceiver = null
|
||||
* For a::memberExtM dispatchReceiver = ExplicitValueReceiver, extensionReceiver = ExplicitValueReceiver
|
||||
*
|
||||
* For class B with companion object B::companionM dispatchReceiver = BoundValueReference
|
||||
*/
|
||||
class CallableReferenceResolutionCandidate(
|
||||
val candidate: CallableDescriptor,
|
||||
val dispatchReceiver: CallableReceiver?,
|
||||
val extensionReceiver: CallableReceiver?,
|
||||
val explicitReceiverKind: ExplicitReceiverKind,
|
||||
val reflectionCandidateType: UnwrappedType,
|
||||
val callableReferenceAdaptation: CallableReferenceAdaptation?,
|
||||
val kotlinCall: CallableReferenceResolutionAtom,
|
||||
override val callComponents: KotlinCallComponents,
|
||||
override val scopeTower: ImplicitScopeTower,
|
||||
override val resolutionCallbacks: KotlinResolutionCallbacks,
|
||||
val expectedType: UnwrappedType?,
|
||||
override val baseSystem: ConstraintStorage?
|
||||
) : ResolutionCandidate() {
|
||||
override val variableCandidateIfInvoke: ResolutionCandidate? = null
|
||||
override val knownTypeParametersResultingSubstitutor: TypeSubstitutor? = null // callable reference's rhs doesn't have type parameters
|
||||
|
||||
override val resolvedCall = ResolvedCallableReferenceCallAtom(
|
||||
kotlinCall.call, candidate, explicitReceiverKind,
|
||||
if (dispatchReceiver != null) ReceiverExpressionKotlinCallArgument(dispatchReceiver.receiver) else null,
|
||||
if (extensionReceiver != null) ReceiverExpressionKotlinCallArgument(extensionReceiver.receiver) else null,
|
||||
reflectionCandidateType,
|
||||
candidate = this
|
||||
)
|
||||
|
||||
override fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom) {} // there aren't nested resolved primitives for callable references
|
||||
override fun getSubResolvedAtoms(): List<ResolvedAtom> = emptyList()
|
||||
|
||||
var freshVariablesSubstitutor: FreshVariableNewTypeSubstitutor? = null
|
||||
internal set
|
||||
|
||||
val numDefaults get() = callableReferenceAdaptation?.defaults ?: 0
|
||||
}
|
||||
+50
-51
@@ -3,60 +3,62 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.model
|
||||
package org.jetbrains.kotlin.resolve.calls.components.candidate
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.components.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.Candidate
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
* baseSystem contains all information from arguments, i.e. it is union of all system of arguments
|
||||
* Also by convention we suppose that baseSystem has no contradiction
|
||||
*/
|
||||
class KotlinResolutionCandidate(
|
||||
val callComponents: KotlinCallComponents,
|
||||
val resolutionCallbacks: KotlinResolutionCallbacks,
|
||||
val callableReferenceResolver: CallableReferenceResolver,
|
||||
val scopeTower: ImplicitScopeTower,
|
||||
private val baseSystem: ConstraintStorage,
|
||||
val resolvedCall: MutableResolvedCallAtom,
|
||||
val knownTypeParametersResultingSubstitutor: TypeSubstitutor? = null,
|
||||
private val resolutionSequence: List<ResolutionPart> = resolvedCall.atom.callKind.resolutionSequence
|
||||
) : Candidate, KotlinDiagnosticsHolder {
|
||||
val diagnosticsFromResolutionParts = arrayListOf<KotlinCallDiagnostic>() // TODO: this is mutable list, take diagnostics only once!
|
||||
sealed class ResolutionCandidate : Candidate, KotlinDiagnosticsHolder {
|
||||
abstract val resolvedCall: MutableResolvedCallAtom
|
||||
abstract val callComponents: KotlinCallComponents
|
||||
abstract fun getSubResolvedAtoms(): List<ResolvedAtom>
|
||||
abstract fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom)
|
||||
abstract val variableCandidateIfInvoke: ResolutionCandidate?
|
||||
abstract val scopeTower: ImplicitScopeTower
|
||||
abstract val knownTypeParametersResultingSubstitutor: TypeSubstitutor?
|
||||
abstract val resolutionCallbacks: KotlinResolutionCallbacks
|
||||
protected abstract val baseSystem: ConstraintStorage?
|
||||
|
||||
override fun addDiagnostic(diagnostic: KotlinCallDiagnostic) {
|
||||
mutableDiagnostics.add(diagnostic)
|
||||
currentApplicability = minOf(diagnostic.candidateApplicability, currentApplicability)
|
||||
}
|
||||
|
||||
private val variableApplicability
|
||||
get() = variableCandidateIfInvoke?.resultingApplicability ?: CandidateApplicability.RESOLVED
|
||||
|
||||
val descriptor: CallableDescriptor get() = resolvedCall.candidateDescriptor
|
||||
|
||||
protected val mutableDiagnostics: ArrayList<KotlinCallDiagnostic> = arrayListOf()
|
||||
|
||||
open val resolutionSequence: List<ResolutionPart> get() = resolvedCall.atom.callKind.resolutionSequence
|
||||
private var newSystem: NewConstraintSystemImpl? = null
|
||||
private var currentApplicability = CandidateApplicability.RESOLVED
|
||||
private var subResolvedAtoms: MutableList<ResolvedAtom> = arrayListOf()
|
||||
|
||||
private val stepCount = resolutionSequence.sumOf { it.run { workCount() } }
|
||||
private var step = 0
|
||||
val diagnostics: List<KotlinCallDiagnostic> = mutableDiagnostics
|
||||
|
||||
fun getSystem(): NewConstraintSystem {
|
||||
if (newSystem == null) {
|
||||
newSystem =
|
||||
NewConstraintSystemImpl(callComponents.constraintInjector, callComponents.builtIns, callComponents.kotlinTypeRefiner)
|
||||
newSystem!!.addOtherSystem(baseSystem)
|
||||
newSystem = NewConstraintSystemImpl(
|
||||
callComponents.constraintInjector, callComponents.builtIns, callComponents.kotlinTypeRefiner
|
||||
)
|
||||
if (baseSystem != null) {
|
||||
newSystem!!.addOtherSystem(baseSystem!!)
|
||||
}
|
||||
}
|
||||
return newSystem!!
|
||||
}
|
||||
|
||||
internal val csBuilder get() = getSystem().getBuilder()
|
||||
|
||||
override fun addDiagnostic(diagnostic: KotlinCallDiagnostic) {
|
||||
diagnosticsFromResolutionParts.add(diagnostic)
|
||||
currentApplicability = minOf(diagnostic.candidateApplicability, currentApplicability)
|
||||
}
|
||||
|
||||
fun getSubResolvedAtoms(): List<ResolvedAtom> = subResolvedAtoms
|
||||
|
||||
fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom) {
|
||||
subResolvedAtoms.add(resolvedAtom)
|
||||
}
|
||||
private val stepCount get() = resolutionSequence.sumOf { it.run { workCount() } }
|
||||
private var step = 0
|
||||
|
||||
private fun processParts(stopOnFirstError: Boolean) {
|
||||
if (stopOnFirstError && step > 0) return // error already happened
|
||||
@@ -83,7 +85,7 @@ class KotlinResolutionCandidate(
|
||||
partIndex++
|
||||
}
|
||||
if (step == stepCount) {
|
||||
resolvedCall.setAnalyzedResults(subResolvedAtoms)
|
||||
resolvedCall.setAnalyzedResults(getSubResolvedAtoms())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,35 +100,32 @@ class KotlinResolutionCandidate(
|
||||
return false
|
||||
}
|
||||
|
||||
val variableCandidateIfInvoke: KotlinResolutionCandidate?
|
||||
get() = callComponents.statelessCallbacks.getVariableCandidateIfInvoke(resolvedCall.atom)
|
||||
|
||||
private val variableApplicability
|
||||
get() = variableCandidateIfInvoke?.resultingApplicability ?: CandidateApplicability.RESOLVED
|
||||
protected var currentApplicability: CandidateApplicability = CandidateApplicability.RESOLVED
|
||||
|
||||
override val isSuccessful: Boolean
|
||||
get() {
|
||||
processParts(stopOnFirstError = true)
|
||||
return currentApplicability.isSuccess && variableApplicability.isSuccess && !getSystem().hasContradiction
|
||||
return resultingApplicabilities.minOrNull()!!.isSuccess && !getSystem().hasContradiction
|
||||
}
|
||||
|
||||
val resultingApplicabilities: Array<CandidateApplicability>
|
||||
get() = arrayOf(currentApplicability, getResultApplicability(getSystem().errors), variableApplicability)
|
||||
|
||||
override val resultingApplicability: CandidateApplicability
|
||||
get() {
|
||||
processParts(stopOnFirstError = false)
|
||||
|
||||
val systemApplicability = getResultApplicability(getSystem().errors)
|
||||
return minOf(currentApplicability, systemApplicability, variableApplicability)
|
||||
return resultingApplicabilities.minOrNull()!!
|
||||
}
|
||||
|
||||
override fun addCompatibilityWarning(other: Candidate) {
|
||||
if (this !== other && other is KotlinResolutionCandidate) {
|
||||
addDiagnostic(CompatibilityWarning(other.resolvedCall.candidateDescriptor))
|
||||
if (other is ResolutionCandidate && this !== other && this::class == other::class) {
|
||||
addDiagnostic(CompatibilityWarning(other.descriptor))
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
val descriptor = DescriptorRenderer.COMPACT.render(resolvedCall.candidateDescriptor)
|
||||
val okOrFail = if (currentApplicability.isSuccess) "OK" else "FAIL"
|
||||
val okOrFail = if (resultingApplicabilities.minOrNull()!!.isSuccess) "OK" else "FAIL"
|
||||
val step = "$step/$stepCount"
|
||||
return "$okOrFail($step): $descriptor"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.components.candidate
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.components.ErrorDescriptorResolutionPart
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallComponents
|
||||
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCallAtom
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolutionPart
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower
|
||||
|
||||
class SimpleErrorResolutionCandidate(
|
||||
callComponents: KotlinCallComponents,
|
||||
resolutionCallbacks: KotlinResolutionCallbacks,
|
||||
scopeTower: ImplicitScopeTower,
|
||||
baseSystem: ConstraintStorage,
|
||||
resolvedCall: MutableResolvedCallAtom
|
||||
) : SimpleResolutionCandidate(callComponents, resolutionCallbacks, scopeTower, baseSystem, resolvedCall) {
|
||||
override val resolutionSequence: List<ResolutionPart> = listOf(ErrorDescriptorResolutionPart)
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.components.candidate
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallComponents
|
||||
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCallAtom
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedAtom
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
/**
|
||||
* baseSystem contains all information from arguments, i.e. it is union of all system of arguments
|
||||
* Also by convention we suppose that baseSystem has no contradiction
|
||||
*/
|
||||
open class SimpleResolutionCandidate(
|
||||
override val callComponents: KotlinCallComponents,
|
||||
override val resolutionCallbacks: KotlinResolutionCallbacks,
|
||||
override val scopeTower: ImplicitScopeTower,
|
||||
override val baseSystem: ConstraintStorage,
|
||||
override val resolvedCall: MutableResolvedCallAtom,
|
||||
override val knownTypeParametersResultingSubstitutor: TypeSubstitutor? = null,
|
||||
) : ResolutionCandidate() {
|
||||
private var subResolvedAtoms: MutableList<ResolvedAtom> = arrayListOf()
|
||||
|
||||
override val variableCandidateIfInvoke: ResolutionCandidate?
|
||||
get() = callComponents.statelessCallbacks.getVariableCandidateIfInvoke(resolvedCall.atom)
|
||||
|
||||
override fun getSubResolvedAtoms(): List<ResolvedAtom> = subResolvedAtoms
|
||||
|
||||
override fun addResolvedKtPrimitive(resolvedAtom: ResolvedAtom) {
|
||||
subResolvedAtoms.add(resolvedAtom)
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -6,13 +6,14 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.components
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
|
||||
interface ParameterTypeConversion {
|
||||
fun conversionDefinitelyNotNeeded(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
expectedParameterType: UnwrappedType
|
||||
): Boolean
|
||||
@@ -21,7 +22,7 @@ interface ParameterTypeConversion {
|
||||
fun conversionIsNeededAfterSubtypingCheck(argument: KotlinCallArgument): Boolean
|
||||
|
||||
fun convertParameterType(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
parameter: ParameterDescriptor,
|
||||
expectedParameterType: UnwrappedType
|
||||
@@ -30,7 +31,7 @@ interface ParameterTypeConversion {
|
||||
|
||||
object TypeConversions {
|
||||
fun performCompositeConversionBeforeSubtyping(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
candidateParameter: ParameterDescriptor,
|
||||
candidateExpectedType: UnwrappedType,
|
||||
@@ -61,7 +62,7 @@ object TypeConversions {
|
||||
}
|
||||
|
||||
fun performCompositeConversionAfterSubtyping(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
candidateParameter: ParameterDescriptor,
|
||||
candidateExpectedType: UnwrappedType,
|
||||
@@ -86,7 +87,7 @@ object TypeConversions {
|
||||
}
|
||||
|
||||
private fun performConversionAfterSubtyping(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
candidateParameter: ParameterDescriptor,
|
||||
candidateExpectedType: UnwrappedType,
|
||||
@@ -103,7 +104,7 @@ object TypeConversions {
|
||||
}
|
||||
|
||||
private fun performConversionBeforeSubtyping(
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: ResolutionCandidate,
|
||||
argument: KotlinCallArgument,
|
||||
candidateParameter: ParameterDescriptor,
|
||||
candidateExpectedType: UnwrappedType,
|
||||
|
||||
+1
-1
@@ -282,7 +282,7 @@ class KotlinConstraintSystemCompleter(
|
||||
|
||||
fun prepareLambdaAtomForFactoryPattern(
|
||||
atom: ResolvedLambdaAtom,
|
||||
candidate: KotlinResolutionCandidate,
|
||||
candidate: SimpleResolutionCandidate,
|
||||
diagnosticsHolder: KotlinDiagnosticsHolder,
|
||||
): ResolvedLambdaAtom {
|
||||
val returnVariable = TypeVariableForLambdaReturnType(candidate.callComponents.builtIns, "_R")
|
||||
|
||||
+5
-5
@@ -38,7 +38,7 @@ class CallableReferencesCandidateFactory(
|
||||
val expectedType: UnwrappedType?,
|
||||
private val csBuilder: ConstraintSystemOperation,
|
||||
private val resolutionCallbacks: KotlinResolutionCallbacks
|
||||
) : CandidateFactory<CallableReferenceCandidate> {
|
||||
) : CandidateFactory<CallableReferenceResolutionCandidate> {
|
||||
|
||||
fun createCallableProcessor(explicitReceiver: DetailedReceiver?) =
|
||||
createCallableReferenceProcessor(scopeTower, argument.rhsName, this, explicitReceiver)
|
||||
@@ -47,7 +47,7 @@ class CallableReferencesCandidateFactory(
|
||||
towerCandidate: CandidateWithBoundDispatchReceiver,
|
||||
explicitReceiverKind: ExplicitReceiverKind,
|
||||
extensionReceiver: ReceiverValueWithSmartCastInfo?
|
||||
): CallableReferenceCandidate {
|
||||
): CallableReferenceResolutionCandidate {
|
||||
|
||||
val dispatchCallableReceiver =
|
||||
towerCandidate.dispatchReceiver?.let { toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.DISPATCH_RECEIVER) }
|
||||
@@ -63,8 +63,8 @@ class CallableReferencesCandidateFactory(
|
||||
callComponents.builtIns
|
||||
)
|
||||
|
||||
fun createReferenceCandidate(): CallableReferenceCandidate =
|
||||
CallableReferenceCandidate(
|
||||
fun createReferenceCandidate(): CallableReferenceResolutionCandidate =
|
||||
CallableReferenceResolutionCandidate(
|
||||
candidateDescriptor, dispatchCallableReceiver, extensionCallableReceiver,
|
||||
explicitReceiverKind, reflectionCandidateType, callableReferenceAdaptation, diagnostics
|
||||
)
|
||||
@@ -92,7 +92,7 @@ class CallableReferencesCandidateFactory(
|
||||
}
|
||||
|
||||
if (candidateDescriptor !is CallableMemberDescriptor) {
|
||||
return CallableReferenceCandidate(
|
||||
return CallableReferenceResolutionCandidate(
|
||||
candidateDescriptor, dispatchCallableReceiver, extensionCallableReceiver,
|
||||
explicitReceiverKind, reflectionCandidateType, callableReferenceAdaptation,
|
||||
listOf(NotCallableMemberReference(argument, candidateDescriptor))
|
||||
+4
-6
@@ -19,7 +19,8 @@ package org.jetbrains.kotlin.resolve.calls.model
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintWarning
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
||||
@@ -193,16 +194,13 @@ class SuperAsExtensionReceiver(val receiver: SimpleKotlinCallArgument) : KotlinC
|
||||
}
|
||||
|
||||
// candidates result
|
||||
class NoneCandidatesCallDiagnostic(val kotlinCall: KotlinCall) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||
class NoneCandidatesCallDiagnostic : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||
override fun report(reporter: DiagnosticReporter) {
|
||||
reporter.onCall(this)
|
||||
}
|
||||
}
|
||||
|
||||
class ManyCandidatesCallDiagnostic(
|
||||
val kotlinCall: KotlinCall,
|
||||
val candidates: Collection<KotlinResolutionCandidate>
|
||||
) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||
class ManyCandidatesCallDiagnostic(val candidates: Collection<ResolutionCandidate>) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||
override fun report(reporter: DiagnosticReporter) {
|
||||
reporter.onCall(this)
|
||||
}
|
||||
|
||||
+8
-15
@@ -19,24 +19,16 @@ package org.jetbrains.kotlin.resolve.calls.model
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDynamicExtensionAnnotation
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConversionOracle
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConversionResolver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
|
||||
|
||||
class KotlinCallComponents(
|
||||
@@ -52,6 +44,7 @@ class KotlinCallComponents(
|
||||
val kotlinTypeChecker: NewKotlinTypeChecker,
|
||||
val lookupTracker: LookupTracker,
|
||||
val kotlinTypeRefiner: KotlinTypeRefiner,
|
||||
val callableReferenceArgumentResolver: CallableReferenceArgumentResolver
|
||||
)
|
||||
|
||||
class SimpleCandidateFactory(
|
||||
@@ -60,7 +53,7 @@ class SimpleCandidateFactory(
|
||||
val kotlinCall: KotlinCall,
|
||||
val resolutionCallbacks: KotlinResolutionCallbacks,
|
||||
val callableReferenceResolver: CallableReferenceResolver
|
||||
) : CandidateFactory<KotlinResolutionCandidate> {
|
||||
) : CandidateFactory<SimpleResolutionCandidate> {
|
||||
val inferenceSession: InferenceSession = resolutionCallbacks.inferenceSession
|
||||
|
||||
val baseSystem: ConstraintStorage
|
||||
@@ -102,7 +95,7 @@ class SimpleCandidateFactory(
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun createCandidate(givenCandidate: GivenCandidate): KotlinResolutionCandidate {
|
||||
fun createCandidate(givenCandidate: GivenCandidate): SimpleResolutionCandidate {
|
||||
val isSafeCall = (kotlinCall.explicitReceiver as? SimpleKotlinCallArgument)?.isSafeCall ?: false
|
||||
|
||||
val explicitReceiverKind =
|
||||
@@ -120,7 +113,7 @@ class SimpleCandidateFactory(
|
||||
towerCandidate: CandidateWithBoundDispatchReceiver,
|
||||
explicitReceiverKind: ExplicitReceiverKind,
|
||||
extensionReceiver: ReceiverValueWithSmartCastInfo?
|
||||
): KotlinResolutionCandidate {
|
||||
): SimpleResolutionCandidate {
|
||||
val dispatchArgumentReceiver = createReceiverArgument(
|
||||
kotlinCall.getExplicitDispatchReceiver(explicitReceiverKind),
|
||||
towerCandidate.dispatchReceiver
|
||||
@@ -141,14 +134,14 @@ class SimpleCandidateFactory(
|
||||
extensionArgumentReceiver: SimpleKotlinCallArgument?,
|
||||
initialDiagnostics: Collection<KotlinCallDiagnostic>,
|
||||
knownSubstitutor: TypeSubstitutor?
|
||||
): KotlinResolutionCandidate {
|
||||
): SimpleResolutionCandidate {
|
||||
val resolvedKtCall = MutableResolvedCallAtom(
|
||||
kotlinCall, descriptor, explicitReceiverKind,
|
||||
dispatchArgumentReceiver, extensionArgumentReceiver
|
||||
)
|
||||
|
||||
if (ErrorUtils.isError(descriptor)) {
|
||||
return KotlinResolutionCandidate(
|
||||
return SimpleResolutionCandidate(
|
||||
callComponents,
|
||||
resolutionCallbacks,
|
||||
callableReferenceResolver,
|
||||
@@ -160,7 +153,7 @@ class SimpleCandidateFactory(
|
||||
)
|
||||
}
|
||||
|
||||
val candidate = KotlinResolutionCandidate(
|
||||
val candidate = SimpleResolutionCandidate(
|
||||
callComponents, resolutionCallbacks, callableReferenceResolver, scopeTower, baseSystem, resolvedKtCall, knownSubstitutor
|
||||
)
|
||||
|
||||
@@ -183,7 +176,7 @@ class SimpleCandidateFactory(
|
||||
return candidate
|
||||
}
|
||||
|
||||
fun createErrorCandidate(): KotlinResolutionCandidate {
|
||||
fun createErrorCandidate(): SimpleResolutionCandidate {
|
||||
val errorScope = ErrorUtils.createErrorScope("Error resolution candidate for call $kotlinCall")
|
||||
val errorDescriptor = if (kotlinCall.callKind == KotlinCallKind.VARIABLE) {
|
||||
errorScope.getContributedVariables(kotlinCall.name, scopeTower.location)
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.model
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.ReturnArgumentsInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper
|
||||
import org.jetbrains.kotlin.resolve.calls.components.extractInputOutputTypesFromCallableReferenceExpectedType
|
||||
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewT
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
@@ -167,13 +168,13 @@ abstract class ResolvedCallableReferenceAtom(
|
||||
override val atom: CallableReferenceKotlinCallArgument,
|
||||
override val expectedType: UnwrappedType?
|
||||
) : PostponedResolvedAtom() {
|
||||
var candidate: CallableReferenceCandidate? = null
|
||||
var candidate: CallableReferenceResolutionCandidate? = null
|
||||
private set
|
||||
|
||||
var completed: Boolean = false
|
||||
|
||||
fun setAnalyzedResults(
|
||||
candidate: CallableReferenceCandidate?,
|
||||
candidate: CallableReferenceResolutionCandidate?,
|
||||
subResolvedAtoms: List<ResolvedAtom>
|
||||
) {
|
||||
this.candidate = candidate
|
||||
@@ -292,7 +293,7 @@ class AllCandidatesResolutionResult(
|
||||
val allCandidates: Collection<CandidateWithDiagnostics>
|
||||
) : CallResolutionResult(null, emptyList(), ConstraintStorage.Empty)
|
||||
|
||||
data class CandidateWithDiagnostics(val candidate: KotlinResolutionCandidate, val diagnostics: List<KotlinCallDiagnostic>)
|
||||
data class CandidateWithDiagnostics(val candidate: ResolutionCandidate, val diagnostics: List<KotlinCallDiagnostic>)
|
||||
|
||||
fun CallResolutionResult.resultCallAtom(): ResolvedCallAtom? =
|
||||
if (this is SingleCallResolutionResult) resultCallAtom else null
|
||||
|
||||
+7
-6
@@ -21,7 +21,8 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
@@ -37,13 +38,13 @@ import org.jetbrains.kotlin.utils.SmartList
|
||||
|
||||
|
||||
abstract class ResolutionPart {
|
||||
abstract fun KotlinResolutionCandidate.process(workIndex: Int)
|
||||
abstract fun ResolutionCandidate.process(workIndex: Int)
|
||||
|
||||
open fun KotlinResolutionCandidate.workCount(): Int = 1
|
||||
open fun ResolutionCandidate.workCount(): Int = 1
|
||||
|
||||
// helper functions
|
||||
protected inline val KotlinResolutionCandidate.candidateDescriptor get() = resolvedCall.candidateDescriptor
|
||||
protected inline val KotlinResolutionCandidate.kotlinCall get() = resolvedCall.atom
|
||||
protected inline val ResolutionCandidate.candidateDescriptor get() = resolvedCall.candidateDescriptor
|
||||
protected inline val ResolutionCandidate.kotlinCall get() = resolvedCall.atom
|
||||
}
|
||||
|
||||
interface KotlinDiagnosticsHolder {
|
||||
@@ -139,7 +140,7 @@ class MutableResolvedCallAtom(
|
||||
override fun toString(): String = "$atom, candidate = $candidateDescriptor"
|
||||
}
|
||||
|
||||
fun KotlinResolutionCandidate.markCandidateForCompatibilityResolve() {
|
||||
fun ResolutionCandidate.markCandidateForCompatibilityResolve() {
|
||||
if (callComponents.languageVersionSettings.supportsFeature(LanguageFeature.DisableCompatibilityModeForNewInference)) return
|
||||
addDiagnostic(LowerPriorityToPreserveCompatibility.asDiagnostic())
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ interface CandidateFactory<out C : Candidate> {
|
||||
explicitReceiverKind: ExplicitReceiverKind,
|
||||
extensionReceiver: ReceiverValueWithSmartCastInfo?
|
||||
): C
|
||||
|
||||
fun createErrorCandidate(): C
|
||||
}
|
||||
|
||||
interface CandidateFactoryProviderForInvoke<C : Candidate> {
|
||||
|
||||
Reference in New Issue
Block a user