Files
kotlin-fork/compiler/testData/diagnostics/testsWithStdLib/kt55503_2.kt
T
Nikolay Lunyak 603b46e531 [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
2023-02-03 08:26:17 +00:00

33 lines
463 B
Kotlin
Vendored

// FIR_IDENTICAL
// WITH_STDLIB
// FIR_DUMP
// FILE: First.kt
package sample.pack
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@kotlin.internal.HidesMembers
fun A.forEach() = "::A.forEach"
class A {
fun B.forEach() = "A::B.forEach"
}
class B
// FILE: Second.kt
package sample
import sample.pack.*
fun box() {
return with(A()) {
with(B()) {
// Both K1 & K2 resolve to A::B.check
forEach()
}
}
}