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

Fix S2589 FP: Constants not correctly evaluated for S2589 #8512

Closed
nrankin18 opened this issue Jan 3, 2024 · 1 comment
Closed

Fix S2589 FP: Constants not correctly evaluated for S2589 #8512

nrankin18 opened this issue Jan 3, 2024 · 1 comment

Comments

@nrankin18
Copy link

nrankin18 commented Jan 3, 2024

Description

S2589 does not correctly evaluate constant and considers code to be unreachable.

Repro steps

private const int SOME_CONST = 3;

private void Test(List<string> elements)
{
	int i = 0;
	foreach (string s in elements) {
		i++;
		if (i >= SOME_CONST) { // S2589 is thrown flagging the conditional as always false
			Console.WriteLine("Here");
		}
	}
}

Expected behavior

S2589 should not be raised because the conditional is passable when elements.Count >= SOME_CONST

Actual behavior

S2589 is thrown.

Known workarounds

None.

Related information

  • Related information
  • C# version: 10.0
  • Visual Studio version: 17.8.2
  • dotnet version : net6.0
  • Operating System: Windows 11 Home 10.0.22000 Build 22000
@Tim-Pohlmann
Copy link
Contributor

Hello @nrankin18, thank you for the report. The issue is related to loop handling. It will be fixed by #8474.

@Tim-Pohlmann Tim-Pohlmann closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2024
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

2 participants