Implement missing invoke resolution branch with context receivers

#KT-61937 fixed
Note: the current implementation only resolves for a single receiver
in each group. See KT-62712 and KT-62709 for the followup.
This commit is contained in:
Ilya Chernikov
2023-10-18 10:57:52 +02:00
committed by Space Team
parent b89d8a65a1
commit 268d058bbb
17 changed files with 172 additions and 1 deletions
@@ -443,6 +443,22 @@ private class InvokeFunctionResolveTask(
ExplicitReceiverKind.DISPATCH_RECEIVER
)
}
for ((depth, contextReceiverGroup) in towerDataElementsForName.contextReceiverGroups) {
val towerGroup =
TowerGroup
.ContextReceiverGroup(depth)
.InvokeExtensionWithImplicitReceiver
.withGivenInvokeReceiverGroup(InvokeResolvePriority.INVOKE_EXTENSION)
val towerLevel = invokeReceiverValue.toMemberScopeTowerLevel()
// TODO: resolve for all receivers in the group, but implement the ambiguity diagnostics first. See KT-62712 and KT-69709
contextReceiverGroup.singleOrNull()?.let { contextReceiverValue ->
processLevel(
towerLevel,
info.withReceiverAsArgument(contextReceiverValue.receiverExpression), towerGroup,
ExplicitReceiverKind.EXTENSION_RECEIVER
)
}
}
}
private suspend fun processLevelForRegularInvoke(
@@ -542,7 +542,12 @@ class BodyResolveContext(
val forMembersResolution =
statics
.addLocalScope(parameterScope)
.addContextReceiverGroup(towerElementsForScript.implicitReceivers)
// TODO: temporary solution for avoiding problem described in KT-62712, flatten back after fix
.let { baseCtx ->
towerElementsForScript.implicitReceivers.fold(baseCtx) { ctx, it ->
ctx.addContextReceiverGroup(listOf(it))
}
}
val newContexts = FirRegularTowerDataContexts(
regular = forMembersResolution,