Go

Go

Made by DeepSource

Audit required: Possibly odd compound for assignment operators: '+=' or '-=' GO-E1009

Bug risk
Critical

The addition (+=) and negative (-=) assignments add and subtract, respectively, the value of the right operand to the left operand and update the same. For the following cases, they might have odd compounds, and there might be a bug risk:

x += x + y // result: 2x + y
x += x - y // result: 2x - y
x -= x + y // result: -y
x -= x - y // result: y

It is recommended to audit this manually and then decide whether to fix the issue or ignore it.

Bad practice

// WARNING: Please audit before fixing this issue
x += x + y // result: 2x + y
x += x - y // result: 2x - y
x -= x + y // result: -y
x -= x - y // result: y

Recommended

// WARNING: Please audit before fixing this issue
x += y  // result: x + y
x += -y // result: x - y
x -= y  // result: x - y
x -= -y // result: x + y