K2: Refine handling of Delegate resolution mode
- Move it out of the ContextDependent hierarchy
- Get rid of many controversial checks that were necessary because
Delegate was a ContextDependent inheritor
- Actually fix semantics for lambda processing
Previously, lambdas as delegate expression were not being analyzed
thus leading to an exception (see KT-64635), and this change
forces analyzing them in the same mode as ContextIndependent
(thus `{}` made by default `() -> Unit` leaving to DELEGATE_SPECIAL_FUNCTION_MISSING)
Before this change, new test was failing with an exception.
I've analyzed all `is ContextDependent` and it seems that none of them
is relevant to delegates.
^KT-64635 Fixed
This commit is contained in:
committed by
Space Team
parent
47a51f6499
commit
df2a1d4d02
+38
@@ -0,0 +1,38 @@
|
||||
// ISSUE: KT-64635
|
||||
// FIR_IDENTICAL
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Context
|
||||
|
||||
interface MyReadOnlyProperty<in T, out V> {
|
||||
operator fun getValue(thisRef: T, property: KProperty<*>): V
|
||||
}
|
||||
|
||||
open class NodeHolder {
|
||||
operator fun ((Context).() -> Unit).provideDelegate(
|
||||
thisRef: Any?,
|
||||
prop: KProperty<*>
|
||||
): MyReadOnlyProperty<Any?, Unit> = TODO()
|
||||
}
|
||||
|
||||
class SubClass1 : NodeHolder() {
|
||||
val foo: (Context).() -> Unit = {}
|
||||
val x by foo
|
||||
}
|
||||
|
||||
class SubClass2 : NodeHolder() {
|
||||
val x by <!DELEGATE_SPECIAL_FUNCTION_MISSING!>{}<!>
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val my_holder_works =
|
||||
object : NodeHolder() {
|
||||
val foo: (Context).() -> Unit = {}
|
||||
val x by foo
|
||||
}
|
||||
|
||||
val my_holder_bad =
|
||||
object : NodeHolder() {
|
||||
val x by <!DELEGATE_SPECIAL_FUNCTION_MISSING!>{}<!>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user