ReSharper 2024.1 Help

Code Inspection: Heuristically unreachable case due to integer analysis

Category

Potential Code Quality Issues

ID

UnreachableSwitchCaseDueToIntegerAnalysis

EditorConfig

resharper_unreachable_switch_case_due_to_integer_analysis_highlighting

Default severity

Warning

Language

C#

Requires SWA

No

This inspection reports cases of switch statements that will never be executed according to the results of integer value analysis. The inspection only works if Analyze integer arithmetic is enabled on the Code Inspection | Settings page of ReSharper options Alt+R, O.

Here is an example of annotating the method parameter with [NonNegativeValueAttribute] to refine the analysis within the method body. Knowing that the parameter is non-negative, ReSharper can report redundant cases:

void TestSwitch([NonNegativeValue] int input) { int newValue; switch (input) { case 0: newValue = 1; break; case -1: // Case is heuristically unavailable newValue = 0; break; default: newValue = input; break; } }
Last modified: 15 April 2024