Files
kotlin-fork/compiler/testData/diagnostics/tests/IncDec.fir.kt
T
Kirill Rakhman 3b9724d20e [FIR] Desugar increment/decrement in body resolve phase
The expression needs to be resolved first to determine if there is a
receiver that needs to be extracted to a temporary variable. Also, the
special case for prefix increment/decrement on local variable without
delegates requires resolution to check if the variable is local.

^KT-56771 Fixed
^KT-56659 Fixed
2023-03-02 10:19:57 +00:00

47 lines
1.1 KiB
Kotlin
Vendored

class IncDec() {
operator fun inc() : IncDec = this
operator fun dec() : IncDec = this
}
fun testIncDec() {
var x = IncDec()
x++
++x
x--
--x
x = x++
x = x--
x = ++x
x = --x
}
class WrongIncDec() {
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun inc() : Int = 1
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun dec() : Int = 1
}
fun testWrongIncDec() {
var x = WrongIncDec()
x<!RESULT_TYPE_MISMATCH!>++<!>
<!RESULT_TYPE_MISMATCH!>++x<!>
x<!RESULT_TYPE_MISMATCH!>--<!>
<!RESULT_TYPE_MISMATCH!>--x<!>
}
class UnitIncDec() {
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun inc() : Unit {}
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun dec() : Unit {}
}
fun testUnitIncDec() {
var x = UnitIncDec()
x<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>++<!>
<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>++<!>x
x<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>
<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>x
x = x<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>++<!>
x = x<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>
x = <!INC_DEC_SHOULD_NOT_RETURN_UNIT, INC_DEC_SHOULD_NOT_RETURN_UNIT!>++<!>x
x = <!INC_DEC_SHOULD_NOT_RETURN_UNIT, INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>x
}