Put increment expressions outside of the parent expression or statement

Description

Unlike `i++` (which returns the resulting value of `i+1`, that could be a part of another expression),
`i += 1` (which is the output of our converter) does not return a value.
Thus, if `i += 1` is a part of an expression, need to place it as a separate statement,
and use just `i` in the expression that uses it.

In particular (see ShouldAddDefaultStatementToSwitchBlockWithoutOne test),

converts to:

... but should be:

Tip: see ExpressionAccessor.IsInsideExpression().

Environment

None

Activity

Show:
Alex Petuschak
August 16, 2018, 2:30 PM

Just found that `ShouldAddDefaultStatementToSwitchBlockWithoutOne` test still has the following comment, and this has not been addressed yet:

Alex Bespalov
August 16, 2018, 8:04 PM

, don't see any TODOs in `ShouldAddDefaultStatementToSwitchBlockWithoutOne` in 'IncrementExpressionsToSeparateStatement' branch.

Alex Petuschak
August 17, 2018, 8:56 AM

My mistake.
I've just added back a postfix `++` operator to that test to demonstrate that it is correctly handled.

Alex Bespalov
August 17, 2018, 11:02 AM

we have separate tests for this: like ShouldConvertPostfixInSwitchExpression

Alex Petuschak
August 17, 2018, 11:09 AM

Sounds good.

Assignee

Alex Bespalov

Reporter

Alex Petuschak

Labels

None

Git Branch Name

IncrementExpressionsToSeparateStatement

GitHub Issue

None

Components

Fix versions

Priority

Low
Configure