FIR: Simplify resolution for invokeExtension on implicit extension
This commit is contained in:
@@ -50,7 +50,6 @@ class CandidateFactory private constructor(
|
||||
scope: FirScope?,
|
||||
dispatchReceiverValue: ReceiverValue? = null,
|
||||
extensionReceiverValue: ReceiverValue? = null,
|
||||
builtInExtensionFunctionReceiverValue: ReceiverValue? = null,
|
||||
objectsByName: Boolean = false
|
||||
): Candidate {
|
||||
@Suppress("NAME_SHADOWING")
|
||||
@@ -59,9 +58,7 @@ class CandidateFactory private constructor(
|
||||
val result = Candidate(
|
||||
symbol, dispatchReceiverValue, extensionReceiverValue,
|
||||
explicitReceiverKind, context.inferenceComponents.constraintSystemFactory, baseSystem,
|
||||
builtInExtensionFunctionReceiverValue?.receiverExpression?.let {
|
||||
callInfo.withReceiverAsArgument(it)
|
||||
} ?: callInfo,
|
||||
callInfo,
|
||||
scope,
|
||||
isFromCompanionObjectTypeScope = when (explicitReceiverKind) {
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER -> extensionReceiverValue.isCandidateFromCompanionObjectTypeScope()
|
||||
|
||||
+3
-6
@@ -424,12 +424,9 @@ private class InvokeFunctionResolveTask(
|
||||
.InvokeResolvePriority(InvokeResolvePriority.INVOKE_EXTENSION)
|
||||
|
||||
processLevel(
|
||||
invokeReceiverValue.toMemberScopeTowerLevel(
|
||||
// Try to supply `implicitReceiverValue` as an "x" in "f.invoke(x)"
|
||||
extensionReceiver = implicitReceiverValue,
|
||||
implicitExtensionInvokeMode = true
|
||||
),
|
||||
info, towerGroup,
|
||||
invokeReceiverValue.toMemberScopeTowerLevel(),
|
||||
// Try to supply `implicitReceiverValue` as an "x" in "f.invoke(x)"
|
||||
info.withReceiverAsArgument(implicitReceiverValue.receiverExpression), towerGroup,
|
||||
ExplicitReceiverKind.DISPATCH_RECEIVER
|
||||
)
|
||||
}
|
||||
|
||||
+2
-3
@@ -87,11 +87,10 @@ internal abstract class FirBaseTowerResolveTask(
|
||||
)
|
||||
|
||||
protected fun ReceiverValue.toMemberScopeTowerLevel(
|
||||
extensionReceiver: ReceiverValue? = null,
|
||||
implicitExtensionInvokeMode: Boolean = false
|
||||
extensionReceiver: ReceiverValue? = null
|
||||
) = MemberScopeTowerLevel(
|
||||
components, this,
|
||||
extensionReceiver, implicitExtensionInvokeMode,
|
||||
extensionReceiver,
|
||||
)
|
||||
|
||||
protected inline fun enumerateTowerLevels(
|
||||
|
||||
+1
-2
@@ -116,8 +116,7 @@ class FirTowerResolver(
|
||||
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER,
|
||||
scope,
|
||||
dispatchReceiver,
|
||||
extensionReceiverValue = null,
|
||||
builtInExtensionFunctionReceiverValue = null
|
||||
extensionReceiverValue = null
|
||||
),
|
||||
context
|
||||
)
|
||||
|
||||
-2
@@ -76,7 +76,6 @@ private class TowerScopeLevelProcessor(
|
||||
dispatchReceiverValue: ReceiverValue?,
|
||||
extensionReceiverValue: ReceiverValue?,
|
||||
scope: FirScope,
|
||||
builtInExtensionFunctionReceiverValue: ReceiverValue?,
|
||||
objectsByName: Boolean
|
||||
) {
|
||||
resultCollector.consumeCandidate(
|
||||
@@ -87,7 +86,6 @@ private class TowerScopeLevelProcessor(
|
||||
scope,
|
||||
dispatchReceiverValue,
|
||||
extensionReceiverValue,
|
||||
builtInExtensionFunctionReceiverValue,
|
||||
objectsByName
|
||||
), candidateFactory.context
|
||||
)
|
||||
|
||||
+2
-22
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.HidesMembers
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
|
||||
enum class ProcessResult {
|
||||
@@ -59,7 +58,6 @@ abstract class TowerScopeLevel {
|
||||
dispatchReceiverValue: ReceiverValue?,
|
||||
extensionReceiverValue: ReceiverValue?,
|
||||
scope: FirScope,
|
||||
builtInExtensionFunctionReceiverValue: ReceiverValue? = null,
|
||||
objectsByName: Boolean = false
|
||||
)
|
||||
}
|
||||
@@ -76,7 +74,6 @@ class MemberScopeTowerLevel(
|
||||
private val bodyResolveComponents: BodyResolveComponents,
|
||||
val dispatchReceiverValue: ReceiverValue,
|
||||
private val extensionReceiver: ReceiverValue? = null,
|
||||
private val implicitExtensionInvokeMode: Boolean = false,
|
||||
) : TowerScopeLevel() {
|
||||
private val scopeSession: ScopeSession get() = bodyResolveComponents.scopeSession
|
||||
private val session: FirSession get() = bodyResolveComponents.session
|
||||
@@ -106,9 +103,7 @@ class MemberScopeTowerLevel(
|
||||
val result = mutableListOf<T>()
|
||||
processScopeMembers { candidate ->
|
||||
empty = false
|
||||
if (candidate is FirCallableSymbol<*> &&
|
||||
(implicitExtensionInvokeMode || candidate.hasConsistentExtensionReceiver(extensionReceiver))
|
||||
) {
|
||||
if (candidate is FirCallableSymbol<*> && candidate.hasConsistentExtensionReceiver(extensionReceiver)) {
|
||||
val fir = candidate.fir
|
||||
if ((fir as? FirConstructor)?.isInner == false) {
|
||||
return@processScopeMembers
|
||||
@@ -126,23 +121,12 @@ class MemberScopeTowerLevel(
|
||||
candidatesWithScope: List<Pair<FirScope, T>>
|
||||
) {
|
||||
for ((scope, candidate) in candidatesWithScope) {
|
||||
if (candidate is FirCallableSymbol<*> &&
|
||||
(implicitExtensionInvokeMode || candidate.hasConsistentExtensionReceiver(extensionReceiver))
|
||||
) {
|
||||
if (candidate is FirCallableSymbol<*> && candidate.hasConsistentExtensionReceiver(extensionReceiver)) {
|
||||
output.consumeCandidate(
|
||||
candidate, dispatchReceiverValue,
|
||||
extensionReceiverValue = extensionReceiver,
|
||||
scope
|
||||
)
|
||||
|
||||
if (implicitExtensionInvokeMode) {
|
||||
output.consumeCandidate(
|
||||
candidate, dispatchReceiverValue,
|
||||
extensionReceiverValue = null,
|
||||
scope,
|
||||
builtInExtensionFunctionReceiverValue = this.extensionReceiver
|
||||
)
|
||||
}
|
||||
} else if (candidate is FirClassLikeSymbol<*>) {
|
||||
output.consumeCandidate(candidate, null, extensionReceiver, scope)
|
||||
}
|
||||
@@ -153,10 +137,6 @@ class MemberScopeTowerLevel(
|
||||
info: CallInfo,
|
||||
processor: TowerScopeLevelProcessor<FirFunctionSymbol<*>>
|
||||
): ProcessResult {
|
||||
val isInvoke = info.name == OperatorNameConventions.INVOKE
|
||||
if (implicitExtensionInvokeMode && !isInvoke) {
|
||||
return ProcessResult.FOUND
|
||||
}
|
||||
val lookupTracker = session.lookupTracker
|
||||
return processMembers(processor) { consumer ->
|
||||
withMemberCallLookup(lookupTracker, info) { lookupCtx ->
|
||||
|
||||
Reference in New Issue
Block a user