Skip to content

warning 204 only works on unused variables #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Daniel-Cortez opened this issue Jan 30, 2020 · 5 comments
Closed

warning 204 only works on unused variables #479

Daniel-Cortez opened this issue Jan 30, 2020 · 5 comments

Comments

@Daniel-Cortez
Copy link
Contributor

Daniel-Cortez commented Jan 30, 2020

Issue description:

Warning 204 (symbol is assigned a value that is never used) only works in simple cases when the variable is unused.

main()
{
	new n = 1; // warning 204: symbol is assigned a value that is never used: "n"
}

But if an unused value is assigned after the point where the variable is used, then the compiler won't warn about it:

main()
{
	new n = 1;
	printf("%d", n);
	n = 2; // no warning, even though this assignment is unused
}

Another problem is when the previously assigned value is unused, the compiler doesn't warn about this kind of errors at all:

new x = 1;
x = 2; // again, no warning, even though the previous value (1) is not used

Since the compiler already warns about unused assignments for unused variables, I think it would be beneficial to make it issue warnings in the aforementioned cases as well.

Minimal complete verifiable example (MCVE):

See above.

Workspace Information:

  • Compiler version:
  • Command line arguments provided (or sampctl version):
  • Operating System:
@Daniel-Cortez
Copy link
Contributor Author

Another special case:

new n = 0;
n = 1;

Here new n = 0; has the same effect as new n;, so it would probably make sense to inhibit the warning for such cases.

@stale
Copy link

stale bot commented May 2, 2020

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

@stale stale bot added the state: stale label May 2, 2020
@Daniel-Cortez
Copy link
Contributor Author

To the maintainers: please do not close this issue yet.
Even though #480 was merged, there's still some room for improvement. I have a couple of ideas on how to make the compiler detect more complicated cases of unused assignments, just need some time for implementation. If those ideas don't work out, I'll just close this issue myself.

@stale
Copy link

stale bot commented Aug 29, 2020

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

@stale stale bot added the state: stale label Aug 29, 2020
@Daniel-Cortez
Copy link
Contributor Author

All of the remaining ideas were implemented in #533, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant