Skip to content
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

Warn when comparing a variable with its only possible value #961

Open
VPanteleev-S7 opened this issue Oct 13, 2024 · 0 comments
Open

Warn when comparing a variable with its only possible value #961

VPanteleev-S7 opened this issue Oct 13, 2024 · 0 comments

Comments

@VPanteleev-S7
Copy link

void example1()
{
	int counter;
	if (counter == 0)
		writeln("First run");
	counter++;
}

void example2()
{
	string[string] cache;
	if (cache is null)
		cache = populateCache();
	// ... use cache ...
}

In both cases, we are missing static from the local variable. Though we cannot infer the intent, we can at least determine and point out that comparing the variable with its only possible value at that time doesn't really make sense.

This could be something as complicated as value propagation but also as simple as just checking whether the variable has ever been initialized since it was declared.

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

No branches or pull requests

1 participant