This isn't a good idea at all, but you can produce the C++ behavior by overriding next() in a mutable fashion, e.g.
@groovy.transform.TupleConstructor class Bar { int value Bar next() { ++value this } } Bar b = new Bar(0) ++(++(++b)) assert b.value == 3 But in reality, it's just eliminating the effects/ordering of re-assignment by only keeping one instance of Bar in play. -Joe On Tue, Feb 14, 2017 at 12:10 PM, Jochen Theodorou <blackd...@gmx.org> wrote: > > > On 13.02.2017 23:58, Thibault Kruse wrote: > >> >> >> On Feb 14, 2017 3:52 AM, "Jochen Theodorou" <blackd...@gmx.org >> <mailto:blackd...@gmx.org>> wrote: >> >> >> Options: >> >> (2) do allow these post- and prefix operators only on >> VariableExpressions, making the code above no longer compile >> >> >> Just to be sure, a VariableExpression is an expression consisting only >> if a variable name? >> > > yes, but yes, you are right, there are also PropertyExpressions and > ArrayExpressions... so I was narrowing it down too much. > > And this applies to both the pre and postfix ++ operator? >> So ++i++ would also stop compiling? >> > > yes > > So the question could be rephrased as: is there any good usecase for ++ >> outside the increment of a variable? Like >> x = (((a * b)++)/c)-- >> > > yes... and that even if considering we call next() for ++. I could imagine > some crazy DSL to use this... but should we still consider doing this > breaking change? > > bye Jochen >