Files
kotlin-fork/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt
T
Denis.Zharkov 555d8eeb25 K2: Fix false-positive DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE
For explanation, see nestedPartiallyResolvedCallsSimple.k

The problem was caused by "select" variable is being leaked to the
inference session of delegate while it should not happen because
it doesn't belong to the common system of `KotlinVal { ..` call,
as we complete it with fixing `E` variable during completion
for `A(select(null, fun(): Int { return 1 }))`.

The root of the problem is that we were adding all the partial
nested calls to the session, while in fact we only need there
the top-level one.

^KT-57543 Fixed
2023-04-28 16:20:06 +02:00

53 lines
1.8 KiB
Kotlin
Vendored

package baz
import kotlin.reflect.KProperty
class A(outer: Outer) {
var i: String by + getMyConcreteProperty()
var d: String by getMyConcreteProperty() - 1
var c: String by O.getMyProperty()
var g: String by outer.getContainer().getMyProperty()
var b: String by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(getMyProperty())
var r: String by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(outer.getContainer().getMyProperty())
var e: String by + <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(getMyProperty())
var f: String by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(getMyProperty()) - 1
}
fun <A, B> foo(a: Any?) = MyProperty<A, B>()
fun <A, B> getMyProperty() = MyProperty<A, B>()
fun getMyConcreteProperty() = MyProperty<Any?, String>()
class MyProperty<R, T> {
operator fun getValue(thisRef: R, desc: KProperty<*>): T {
println("get $thisRef ${desc.name}")
return null <!UNCHECKED_CAST!>as T<!>
}
operator fun setValue(thisRef: R, desc: KProperty<*>, value: T) {
println("set $thisRef ${desc.name} $value")
}
}
operator fun <R, T> MyProperty<R, T>.unaryPlus() = MyProperty<R, T>()
operator fun <R, T> MyProperty<R, T>.minus(i: Int) = MyProperty<R, T>()
object O {
fun <A, B> getMyProperty() = MyProperty<A, B>()
}
interface MyPropertyContainer {
fun <R, T> getMyProperty(): MyProperty<R, T>
}
interface Outer {
fun getContainer(): MyPropertyContainer
}
// -----------------
fun println(a: Any?) = a