Files
kotlin-fork/compiler/testData/codegen/box/inference/builderInference/memberScope.kt
T
Simon Ogorodnik 154e53c701 K1: add diagnostic BUILDER_INFERENCE_STUB_RECEIVER
It's reported on receivers in extension function calls with stub type,
as such calls can shadow members of finalized stub types causing
change of resolve when corresponding type argument specified explicitly

It works by checking extension receiver during call resolution parts run
That way we can easily detect if we found an extension applicable to
stub receiver and report call diagnostic for it

KT-53739
2022-08-30 10:19:26 +00:00

77 lines
1.9 KiB
Kotlin
Vendored

// !LANGUAGE: +UnrestrictedBuilderInference
// !DIAGNOSTICS: -DEPRECATION -OPT_IN_IS_NOT_ENABLED
// WITH_STDLIB
// IGNORE_BACKEND_FIR: JVM_IR
// FIR status: NONE_APPLICABLE at all equals calls
import kotlin.experimental.ExperimentalTypeInference
interface TestInterface<R> {
fun emit(r: R)
fun get(): R
}
@OptIn(ExperimentalTypeInference::class)
fun <R1> build(block: TestInterface<R1>.() -> Unit) {}
fun Any.test() {}
fun Any?.test2() {}
fun box(): String {
val ret = build {
emit(1)
emit(null)
// Error, resolved to extension on stub receiver
// get()?.test()
// get()?.test2()
// get().test2()
get()?.hashCode()
get()?.equals(1)
val x = get()
x?.hashCode()
x?.equals(1)
if (get() == null) {}
if (get() === null) {}
if (x != null) {
x?.hashCode()
x?.equals(1)
x.equals("")
x.hashCode()
x.toString()
// Error, resolved to extension on stub receiver
// x.test()
// x?.test2()
// x.test2()
}
if (x == null) {
x?.hashCode()
x?.equals(1)
// x.equals("") // it'd be an error, because here we try to add constraint `Nothing? < Any`
// x.hashCode()
// x.toString()
// x.test()
// Error, resolved to extension on stub receiver
// x?.test2()
// x.test2()
}
if (x === null) {
x?.hashCode()
x?.equals(1)
// x.equals("") // it'd be an error, because here we try to add constraint `Nothing? < Any`
// x.hashCode()
// x.toString()
// x.test()
// Error, resolved to extension on stub receiver
// x?.test2()
// x.test2()
}
""
}
return "OK"
}