rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Unused assignments should be removed

Open aegershman opened this issue 3 years ago • 2 comments

see: https://rules.sonarsource.com/java/tag/unused/RSPEC-1854

A dead store happens when a local variable is assigned a value that is not read by any subsequent instruction. Calculating or retrieving a value only to then overwrite it or throw it away, could indicate a serious error in the code. Even if it’s not an error, it is at best a waste of resources. Therefore all calculated values should be used.

Note, that this problem, "dead code analysis", among others, is one of the posterchild problems solved by representing the tree as a Control Flow Graph.

See also: https://www.cs.utexas.edu/~pingali/CS380C/2020/lectures/CFG.pdf

aegershman avatar Jul 21 '21 17:07 aegershman

Going to close this for now. While we could hack something together now, a more thorough treatment requires support for dataflow analysis that we haven't yet begun to design.

sambsnyd avatar Aug 22 '21 22:08 sambsnyd

Dataflow analysis is in development.

jkschneider avatar Aug 22 '21 23:08 jkschneider