[FIR] KT-55503: Prefer members-extensions over @HidesMembers extensions
Passing `EXTENSION_RECEIVER` when processing `noReceiver` looks like a mistake in general. This change is backed by the `hidesMembers` and `memberWithHidesMemberAnnotationVsMemberWithout` tests. The exact reason with `memberWithHidesMemberAnnotationVsMemberWithout` is that it first checks `@HidesMembers` candidates, only takes the `kotlin/collections/Iterable<T>.forEach`, but then yields `InapplicableWrongReceiver`, because `explicitReceiverKind = EXTENSION_RECEIVER` (which is strange, because we really don't have an explicit receiver). Then we visit the same scope once more (now for all candidates) and take 2 functions: - `kotlin/collections/Iterable<T>.forEach` - `kotlin/sequence/Sequence<T>.forEach` ...and they both result in `RESOLVED`, because this time `explicitReceiverKind = NO_EXPLICIT_RECEIVER`. This change ensures the first candidate we see while checking `@HidesMembers` is taken as `RESOLVED`. ^KT-55503 Fixed
This commit is contained in:
committed by
Space Team
parent
906b16b41e
commit
603b46e531
+17
-21
@@ -278,7 +278,10 @@ internal open class FirTowerResolveTask(
|
||||
) {
|
||||
val explicitReceiverValue = ExpressionReceiverValue(receiver)
|
||||
|
||||
processExtensionsThatHideMembers(info, explicitReceiverValue, parentGroup)
|
||||
processExtensionsThatHideMembers(
|
||||
info, explicitReceiverValue, parentGroup,
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER,
|
||||
)
|
||||
|
||||
// Member scope of expression receiver
|
||||
processLevel(
|
||||
@@ -314,8 +317,6 @@ internal open class FirTowerResolveTask(
|
||||
suspend fun runResolverForNoReceiver(
|
||||
info: CallInfo
|
||||
) {
|
||||
processExtensionsThatHideMembers(info, explicitReceiverValue = null)
|
||||
|
||||
val emptyScopes = mutableSetOf<FirScope>()
|
||||
val implicitReceiverValuesWithEmptyScopes = mutableSetOf<ImplicitReceiverValue<*>>()
|
||||
|
||||
@@ -366,28 +367,19 @@ internal open class FirTowerResolveTask(
|
||||
|
||||
private suspend fun processExtensionsThatHideMembers(
|
||||
info: CallInfo,
|
||||
explicitReceiverValue: ReceiverValue?,
|
||||
parentGroup: TowerGroup = TowerGroup.EmptyRoot
|
||||
receiverValue: ReceiverValue,
|
||||
parentGroup: TowerGroup,
|
||||
explicitReceiverKind: ExplicitReceiverKind,
|
||||
) {
|
||||
// We will process hides members only for function calls with name in HIDES_MEMBERS_NAME_LIST
|
||||
if (info.callKind != CallKind.Function || info.name !in HIDES_MEMBERS_NAME_LIST) return
|
||||
|
||||
val importingScopes = components.fileImportsScope.asReversed()
|
||||
for ((index, topLevelScope) in importingScopes.withIndex()) {
|
||||
if (explicitReceiverValue != null) {
|
||||
processHideMembersLevel(
|
||||
explicitReceiverValue, topLevelScope, info, index, depth = null,
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER, parentGroup
|
||||
)
|
||||
} else {
|
||||
// context?
|
||||
for ((depth, implicitReceiverValue) in towerDataElementsForName.implicitReceivers) {
|
||||
processHideMembersLevel(
|
||||
implicitReceiverValue, topLevelScope, info, index, depth,
|
||||
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, parentGroup
|
||||
)
|
||||
}
|
||||
}
|
||||
processHideMembersLevel(
|
||||
receiverValue, topLevelScope, info, index,
|
||||
explicitReceiverKind, parentGroup
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,6 +403,11 @@ internal open class FirTowerResolveTask(
|
||||
implicitReceiverValuesWithEmptyScopes: MutableSet<ImplicitReceiverValue<*>>,
|
||||
emptyScopes: MutableSet<FirScope>
|
||||
) {
|
||||
processExtensionsThatHideMembers(
|
||||
info, receiver, TowerGroup.EmptyRoot,
|
||||
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER,
|
||||
)
|
||||
|
||||
processLevel(
|
||||
receiver.toMemberScopeTowerLevel(), info, parentGroup.Member,
|
||||
onEmptyLevel = {
|
||||
@@ -485,7 +482,6 @@ internal open class FirTowerResolveTask(
|
||||
topLevelScope: FirScope,
|
||||
info: CallInfo,
|
||||
index: Int,
|
||||
depth: Int?,
|
||||
explicitReceiverKind: ExplicitReceiverKind,
|
||||
parentGroup: TowerGroup
|
||||
) {
|
||||
@@ -494,7 +490,7 @@ internal open class FirTowerResolveTask(
|
||||
extensionReceiver = receiverValue, withHideMembersOnly = true
|
||||
),
|
||||
info,
|
||||
parentGroup.TopPrioritized(index).let { if (depth != null) it.Implicit(depth) else it },
|
||||
parentGroup.TopPrioritized(index),
|
||||
explicitReceiverKind,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user