KT-30020 expressions without resolved calls in augmented assignment LHS
Augmented assignment operator (e.g., '+=') can be resolved to simple
function call ('plusAssign'). In that case, augmented assignment LHS
can be an arbitrary expression, and may have no associated ResolvedCall.
For example:
(a as MutableList<Int>) += 42
Note that it can happen only in case of augmented assignment operator
convention resolution, because all other forms of assignment-like
operator desugaring require some kind of 'store' operation
(property setter, 'set' operator for array element expression, etc),
and should resolve to some combination of calls.
In that case we simply generate LHS on 'load', and throw assertion on
'store'.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
interface X {
|
||||
val xs: MutableList<Any>
|
||||
fun f(): MutableList<Any>
|
||||
}
|
||||
|
||||
fun test(x: X, nx: X?) {
|
||||
x.xs += 1
|
||||
x.f() += 2
|
||||
(x.xs as MutableList<Int>) += 3
|
||||
(x.f() as MutableList<Int>) += 4
|
||||
nx?.xs!! += 5
|
||||
nx?.f()!! += 6
|
||||
}
|
||||
|
||||
fun MutableList<Any>.testExtensionReceiver() {
|
||||
this += 100
|
||||
}
|
||||
|
||||
abstract class AML : MutableList<Int> {
|
||||
fun testExplicitThis() {
|
||||
this += 200
|
||||
}
|
||||
|
||||
inner class Inner {
|
||||
fun testOuterThis() {
|
||||
this@AML += 300
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user