JetBrains Rider 2024.3 Help

Code inspection: Heuristically unreachable switch arm according to integer analysis

This inspection reports arms of switch expressions 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 Editor | Inspection Settings page of JetBrains Rider settings Ctrl+Alt+S.

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, JetBrains Rider can report redundant cases:

void TestSwitch([NonNegativeValue] int input) { var newValue = input switch { 0 => 1, -1 => 0, // Case is heuristically unreachable _ => input, }; }
Last modified: 11 February 2024