K2: Fix ISE from inference on delegate vars with implicit types
See the test data. ISE happened because at some point after incomplete `getValue` resolution of `a` property, we updated in the `transformAccessors` the property type to the `Variable(Y)` type and then used it as a 3rd argument for `setValue` call which is incorrect because the variable belongs to a different constraint system (from `getValue`). Mostly, the fix is just a repeating K1 behavior, namely postponing `setValue` resolution until delegate inference is completed. ^KT-59066 Fixed
This commit is contained in:
committed by
Space Team
parent
b8c4a4c80a
commit
41933facbb
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
// Definitions
|
||||
class M<E>
|
||||
|
||||
operator fun <X> M<out X>.getValue(thisRef: Any?, property: KProperty<*>): String = "value"
|
||||
operator fun <Z> M<in Z>.setValue(thisRef: Any?, property: KProperty<*>, value: Z) {}
|
||||
|
||||
fun <U> m(): M<U> = M()
|
||||
|
||||
// We don't allow to infer type of a delegate expression through a setValue, where the argument (value) is constrained by the return type of a getValue
|
||||
var a by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>m<!>()
|
||||
|
||||
// We infer type of delegate expression through a setValue from the explicit property type
|
||||
var b: String by m()
|
||||
|
||||
fun takeString(v: String) {}
|
||||
|
||||
fun main() {
|
||||
takeString(a)
|
||||
a = "a"
|
||||
takeString(b)
|
||||
b = "b"
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
// Definitions
|
||||
class M<E>
|
||||
|
||||
operator fun <X> M<out X>.getValue(thisRef: Any?, property: KProperty<*>): String = "value"
|
||||
operator fun <Z> M<in Z>.setValue(thisRef: Any?, property: KProperty<*>, value: Z) {}
|
||||
|
||||
fun <U> m(): M<U> = M()
|
||||
|
||||
// We don't allow to infer type of a delegate expression through a setValue, where the argument (value) is constrained by the return type of a getValue
|
||||
var a by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>m<!>()<!>
|
||||
|
||||
// We infer type of delegate expression through a setValue from the explicit property type
|
||||
var b: String by m()
|
||||
|
||||
fun takeString(v: String) {}
|
||||
|
||||
fun main() {
|
||||
takeString(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!>)
|
||||
<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!> = "a"
|
||||
takeString(b)
|
||||
b = "b"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// FIR_IDENTICAL
|
||||
// WITH_STDLIB
|
||||
// WITH_REFLECT
|
||||
// ISSUE: KT-59066
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
interface M< E>
|
||||
|
||||
public operator fun <X, Y : X> M<out X>.getValue(thisRef: Any?, property: KProperty<*>): Y =
|
||||
TODO()
|
||||
|
||||
public operator fun <Z> M<in Z>.setValue(thisRef: Any?, property: KProperty<*>, value: Z) {}
|
||||
|
||||
fun <U> m(u: U): M<U> = TODO()
|
||||
|
||||
var a by m("")
|
||||
|
||||
var b by mutableMapOf("" to 1)
|
||||
|
||||
fun main() {
|
||||
a.length
|
||||
a = "b"
|
||||
|
||||
b = 23
|
||||
b.and(4)
|
||||
}
|
||||
Reference in New Issue
Block a user