bbaldino
08/02/2019, 3:35 PMRuckus
08/02/2019, 3:40 PMinc
and whether it's pre or post depends on how you use it.bbaldino
08/02/2019, 3:40 PMbbaldino
08/02/2019, 3:43 PMinline class WrappingInt(val value: Int) {
operator fun inc(): WrappingInt = plus(1)
operator fun plus(num: Int): WrappingInt = WrappingInt((value + num) and 0xFFFF)
}
fun main() {
var x = WrappingInt(65535)
x++
println(x) // prints 0 (correct)
var y = WrappingInt(65535)
++y
println(y) // prints 65536
}
Ruckus
08/02/2019, 3:48 PMinline
fixes it. I think you've found a bug. You should report it at kotl.in/issue (and link it back here)bbaldino
08/02/2019, 3:48 PMbbaldino
08/02/2019, 3:50 PMRuckus
08/02/2019, 3:50 PMIINC
whereas the postfix is correctly compiled to INVOKESTATIC WrappingInt.inc-impl
. Good catch.bbaldino
08/02/2019, 3:51 PMbbaldino
08/02/2019, 4:04 PMvar z = WrappingInt(65535)
val zz = { ->
++z
println(z)
}
bbaldino
08/02/2019, 4:04 PMbbaldino
08/02/2019, 4:09 PMshould
block for this reason, i think, so this was a sneaky one 😕Ruckus
08/02/2019, 4:52 PM