False positive on rule csharpsquid:S1854

[Developer Edition Version 9.6.1 (build 59531)]

The code smell (csharpsquid:S1854 => remove this useless assignment to the local variable ‘id’.
) is triggered by the last line.

  	int id = 1; 
  	c.f(new c2(id));
  	c.f(new c3(++id));
  	c.f(new c4(++id));
  	c.f(new c5(++id));

From our point of view, the last line has a valid assignment of the variable before the call (++id and not id++), and the rule should not be triggered here.

Hello @julhenau,

Thank you for opening this issue. Your feedback helps us improve our products.

This is not a false positive because you still have an unused assignment in the last statement.

int id = 1; 
c.f(new c2(id++)); // this could be translated as c.f(new c2(id = id + 1)); there is an assignment here that is not used.

In this case, to not raise an issue, it would be better to replace the last statement with c.f(new c5(id + 1)); - so you use the new desired value, but you don’t produce a variable that is unused.

Best Regards,