pawn-lang / compiler

Pawn compiler for SA-MP with bug fixes and new features - runs on Windows, Linux, macOS
Other
303 stars 70 forks source link

Unused compound assignments are not covered by warnings 204 and 240 #645

Open Daniel-Cortez opened 3 years ago

Daniel-Cortez commented 3 years ago

Issue description:

Although the compiler became much better at detecting unused assignments to variables (see #480, #533), it still can't detect unused compound assignments (+=, *= etc.)

Minimal complete verifiable example (MCVE):

main() {
    new x = 0;
    x += 2; // no warning(s), although the modified value is unused
}

Redundant ++ and -- operations (in both pre- and post- forms) too go completely undetected:

main() {
    new x = 0;
    return x++; // no warning(s), although post-increment on a local variable is redundant in return expression
}

While covering such cases with warning 204 ("symbol is assigned a value that is never used") could do, I think making a separate warning for this - something like "variable has its value modified but never used" - would be better, especially for operators ++ and --, where the new warning would be much more descriptive and intuitive.

Workspace Information:

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity.