Files
kotlin-fork/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1571.fir.kt
T
Tianyu Geng fc8d0e3ee0 FIR checkers: report VAL_REASSIGNMENT for assignment operators
Currently VAL_REASSIGNMENT are only reported on direct assignments.
Reassignments in the form of, for example, `+=` are reported as
`VARIABLE_EXPECTED`, which differs from FE1.0.
2021-04-02 13:33:52 +03:00

43 lines
656 B
Kotlin
Vendored

//KT-1571 Frontend fails to check val reassigment for operator overloading.
package kt1571
var c0 = 0
var c1 = 0
var c2 = 0
class A() {
var p = 0
operator fun divAssign(a : Int) {
c1++;
}
operator fun times(a : Int) : A {
c2++;
return this;
}
}
val a : A = A()
get() {
c0++
return field
}
fun box() : String {
a /= 3
if (c0 != 1) {
return "1"
}
if (c1 != 1) {
return "2"
}
<!VAL_REASSIGNMENT!>a<!> *= 3 // a = a * 3, shouldn't be able to do this on val
if (c0 != 2) {
return "3"
}
if (c2 != 1) {
return "4"
}
return "OK"
}