From 4fcb16b4c45f4e6b44d13326221ac03b680dfeff Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Mon, 20 Sep 2021 14:17:34 +0300 Subject: [PATCH] Extract `CallableReferenceCandidate` into separate file --- .../components/CallableReferenceCandidate.kt | 52 +++++++++++++++++++ .../components/CallableReferenceResolution.kt | 36 ------------- 2 files changed, 52 insertions(+), 36 deletions(-) create mode 100644 compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceCandidate.kt diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceCandidate.kt new file mode 100644 index 00000000000..7a84a88869a --- /dev/null +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceCandidate.kt @@ -0,0 +1,52 @@ +/* + * 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 +) : Candidate { + private val mutableDiagnostics = initialDiagnostics.toMutableList() + val diagnostics: List = 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 +} \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index 9c22e82402d..a20ab211a82 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -44,42 +44,6 @@ sealed class CallableReceiver(val receiver: ReceiverValueWithSmartCastInfo) { private val CallableReceiver.asReceiverValueForVisibilityChecks: ReceiverValue get() = receiver.receiverValue -/** - * 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 -) : Candidate { - private val mutableDiagnostics = initialDiagnostics.toMutableList() - val diagnostics: List = 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 -} - class CallableReferenceAdaptation( val argumentTypes: Array, val coercionStrategy: CoercionStrategy,