K2: Rewrite delegate inference

The main idea is getting rid of stub types and using just type variables
See more detailed description at docs/fir/delegated_property_inference.md

The problem with stub types is that they need really special treatment
in many places, and on the other hand, there are no clear contracts on
how they should work (that regularly leads to bugs like KT-59529)

^KT-61060 Fixed
^KT-61075 Fixed
^KT-61077 Fixed
^KT-59529 Fixed
^KT-61633 Related
^KT-61618 Related
^KT-61740 Related
^KT-59107 Related
^KT-61747 Related
^KT-61077 Related
^KT-61781 Related
This commit is contained in:
Denis.Zharkov
2023-08-04 19:52:29 +02:00
committed by Space Team
parent cd5105c133
commit a02cb16fb2
53 changed files with 1183 additions and 381 deletions
@@ -0,0 +1,10 @@
// FIR_IDENTICAL
val test: String by materializeDelegate()
fun <T> materializeDelegate(): Delegate<T> = Delegate()
operator fun <K> K.provideDelegate(receiver: Any?, property: kotlin.reflect.KProperty<*>): K = this
operator fun <X> Delegate<X>.getValue(thisRef: Any?, property: kotlin.reflect.KProperty<*>): X = TODO()
class Delegate<V>
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-61077
class Delegate<T>
operator fun Delegate<*>.getValue(receiver: Any?, p: Any): String = ""
@@ -10,7 +10,7 @@ operator fun <T> String.provideDelegate(receiver: Any?, p: Any) = Delegate<T>()
var test1: String by Delegate()
var test2: String by Delegate<String>()
var test3: String by <!DELEGATE_SPECIAL_FUNCTION_MISSING, DELEGATE_SPECIAL_FUNCTION_MISSING!>"OK"<!>
var test3: String by "OK"
var test4: String by "OK".provideDelegate(null, "")
var test5: String by "OK".provideDelegate<String>(null, "")
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-61077
class Delegate<T>
operator fun Delegate<*>.getValue(receiver: Any?, p: Any): String = ""