Revert "[FE 1.0] Take care callable reference candidates with recursive candidate return type"

This reverts commit d04beaa8bb49c99ceb993f3f7b32169c393b39f4.
This commit is contained in:
Victor Petukhov
2022-05-24 16:00:46 +02:00
committed by teamcity
parent 06deaed3d5
commit 51551998c7
32 changed files with 48 additions and 212 deletions
@@ -8,11 +8,9 @@ package org.jetbrains.kotlin.resolve.calls.components
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.tower.RecursiveCallableReferenceType
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityErrorOnArgument
import org.jetbrains.kotlin.resolve.calls.tower.isInapplicable
import org.jetbrains.kotlin.resolve.calls.model.TypeCheckerHasRanIntoRecursion
class CallableReferenceArgumentResolver(val callableReferenceOverloadConflictResolver: CallableReferenceOverloadConflictResolver) {
fun processCallableReferenceArgument(
@@ -48,7 +46,6 @@ class CallableReferenceArgumentResolver(val callableReferenceOverloadConflictRes
val transformedDiagnostic = when (it) {
is CompatibilityWarning -> CompatibilityWarningOnArgument(argument, it.candidate)
is VisibilityError -> VisibilityErrorOnArgument(argument, it.invisibleMember)
is RecursiveCallableReferenceType -> TypeCheckerHasRanIntoRecursion(argument)
else -> it
}
diagnosticsHolder.addDiagnostic(transformedDiagnostic)
@@ -273,7 +273,7 @@ class KotlinCallCompleter(
constraintSystem.errors.forEach(diagnosticsHolder::addError)
if (returnType is ErrorType && returnType.kind == ErrorTypeKind.RECURSIVE_TYPE) {
diagnosticsHolder.addDiagnostic(TypeCheckerHasRanIntoRecursion())
diagnosticsHolder.addDiagnostic(TypeCheckerHasRanIntoRecursion)
}
}
@@ -18,15 +18,15 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.tower.*
import org.jetbrains.kotlin.resolve.calls.util.ErrorCandidateReason
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.*
import org.jetbrains.kotlin.types.error.ErrorScopeKind
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.expressions.CoercionStrategy
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.utils.SmartList
@@ -43,7 +43,7 @@ class CallableReferencesCandidateFactory(
private val CallableReceiver.asReceiverValueForVisibilityChecks: ReceiverValue
get() = receiver.receiverValue
override fun createErrorCandidate(reason: ErrorCandidateReason): CallableReferenceResolutionCandidate {
override fun createErrorCandidate(): CallableReferenceResolutionCandidate {
val errorScope = ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_RESOLUTION_CANDIDATE, kotlinCall.toString())
val errorDescriptor = errorScope.getContributedFunctions(kotlinCall.rhsName, scopeTower.location).first()
@@ -56,36 +56,21 @@ class CallableReferencesCandidateFactory(
buildTypeWithConversions = kotlinCall is CallableReferenceKotlinCallArgument
)
val candidate = CallableReferenceResolutionCandidate(
return CallableReferenceResolutionCandidate(
errorDescriptor, dispatchReceiver = null, extensionReceiver = null,
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, reflectionCandidateType, callableReferenceAdaptation,
kotlinCall, expectedType, callComponents, scopeTower, resolutionCallbacks, baseSystem
)
when (reason) {
ErrorCandidateReason.TYPE_COMPUTATION_RECURSION -> candidate.addDiagnostic(RecursiveCallableReferenceType)
ErrorCandidateReason.OTHER -> {}
}
return candidate
}
private fun KotlinType.isErrorRecursiveType(): Boolean {
val unwrapped = if (this is WrappedType && isComputed()) unwrap() else this
return unwrapped is ErrorType && unwrapped.kind == ErrorTypeKind.RECURSIVE_TYPE
}
private fun createCandidateInternal(
override fun createCandidate(
towerCandidate: CandidateWithBoundDispatchReceiver,
explicitReceiverKind: ExplicitReceiverKind,
extensionReceiver: ReceiverValueWithSmartCastInfo?
): CallableReferenceResolutionCandidate {
val dispatchCallableReceiver = towerCandidate.dispatchReceiver?.let {
toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.DISPATCH_RECEIVER)
}
val extensionCallableReceiver = extensionReceiver?.let {
toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.EXTENSION_RECEIVER)
}
val dispatchCallableReceiver =
towerCandidate.dispatchReceiver?.let { toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.DISPATCH_RECEIVER) }
val extensionCallableReceiver = extensionReceiver?.let { toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.EXTENSION_RECEIVER) }
val candidateDescriptor = towerCandidate.descriptor
val diagnostics = SmartList<KotlinCallDiagnostic>()
@@ -137,30 +122,6 @@ class CallableReferencesCandidateFactory(
return createCallableReferenceCallCandidate(diagnostics)
}
override fun createCandidate(
towerCandidate: CandidateWithBoundDispatchReceiver,
explicitReceiverKind: ExplicitReceiverKind,
extensionReceiver: ReceiverValueWithSmartCastInfo?
): CallableReferenceResolutionCandidate =
createRecursionTolerantCandidate(towerCandidate, explicitReceiverKind, extensionReceiver) {
createErrorCandidate(ErrorCandidateReason.TYPE_COMPUTATION_RECURSION)
}
private fun createRecursionTolerantCandidate(
towerCandidate: CandidateWithBoundDispatchReceiver,
explicitReceiverKind: ExplicitReceiverKind,
extensionReceiver: ReceiverValueWithSmartCastInfo?,
onRecursion: () -> CallableReferenceResolutionCandidate,
): CallableReferenceResolutionCandidate =
try {
val resolutionCandidate = createCandidateInternal(towerCandidate, explicitReceiverKind, extensionReceiver)
val returnType = resolutionCandidate.candidate.returnType
if (returnType == null || !returnType.isErrorRecursiveType()) resolutionCandidate else onRecursion()
} catch (e: LazyWrappedTypeComputationException) {
onRecursion()
}
/**
* The function is called only inside [NoExplicitReceiverScopeTowerProcessor] with [TowerData.BothTowerLevelAndContextReceiversGroup].
* This case involves only [SimpleCandidateFactory].
@@ -116,14 +116,8 @@ class WrongCountOfTypeArguments(
override fun report(reporter: DiagnosticReporter) = reporter.onTypeArguments(this)
}
class TypeCheckerHasRanIntoRecursion(val onArgument: KotlinCallArgument? = null) : KotlinCallDiagnostic(INAPPLICABLE) {
override fun report(reporter: DiagnosticReporter) {
return if (onArgument != null) {
reporter.onCallArgument(onArgument, this)
} else {
reporter.onCall(this)
}
}
object TypeCheckerHasRanIntoRecursion : KotlinCallDiagnostic(INAPPLICABLE) {
override fun report(reporter: DiagnosticReporter) = reporter.onCall(this)
}
// Callable reference resolution
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
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.calls.util.ErrorCandidateReason
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDynamicExtensionAnnotation
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
import org.jetbrains.kotlin.types.error.ErrorUtils
@@ -164,7 +163,7 @@ class SimpleCandidateFactory(
return candidate
}
override fun createErrorCandidate(reason: ErrorCandidateReason): SimpleResolutionCandidate {
override fun createErrorCandidate(): SimpleResolutionCandidate {
val errorScope = ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_RESOLUTION_CANDIDATE, kotlinCall.toString())
val errorDescriptor = if (kotlinCall.callKind == KotlinCallKind.VARIABLE) {
errorScope.getContributedVariables(kotlinCall.name, scopeTower.location)
@@ -154,7 +154,6 @@ object ResolvedUsingNewFeatures : ResolutionDiagnostic(RESOLVED_NEED_PRESERVE_CO
object UnstableSmartCastDiagnostic : ResolutionDiagnostic(UNSTABLE_SMARTCAST)
object HiddenExtensionRelatedToDynamicTypes : ResolutionDiagnostic(HIDDEN)
object HiddenDescriptor : ResolutionDiagnostic(HIDDEN)
object RecursiveCallableReferenceType : ResolutionDiagnostic(INAPPLICABLE)
object InvokeConventionCallNoOperatorModifier : ResolutionDiagnostic(CONVENTION_ERROR)
object InfixCallNoInfixModifier : ResolutionDiagnostic(CONVENTION_ERROR)
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.util.ErrorCandidateReason
import org.jetbrains.kotlin.resolve.descriptorUtil.HIDES_MEMBERS_NAME_LIST
import org.jetbrains.kotlin.resolve.scopes.HierarchicalScope
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
@@ -48,7 +47,7 @@ interface CandidateFactory<out C : Candidate> {
extensionReceiver: ReceiverValueWithSmartCastInfo?
): C
fun createErrorCandidate(reason: ErrorCandidateReason = ErrorCandidateReason.OTHER): C
fun createErrorCandidate(): C
fun createCandidate(
towerCandidate: CandidateWithBoundDispatchReceiver,
@@ -1,8 +0,0 @@
/*
* Copyright 2010-2022 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.util
enum class ErrorCandidateReason { TYPE_COMPUTATION_RECURSION, OTHER }