Skip to content

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

@Daniel-Cortez

Description

@Daniel-Cortez

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:

  • Compiler version: 3.10.10
  • Command line arguments provided (or sampctl version):
  • Operating System:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions