What does this mean in contrast to "unreachable code detected"?
Asked
Active
Viewed 1.5k times
3 Answers
58
Heuristically unreachable means possibly unreachable code. Unreachable code is certainly unreachable.

Adrian Marinica
- 2,191
- 5
- 29
- 53
-
7I'm finding this cropping up when it's impossible for me or ReSharper to know whether something is always going to be false (or `== null`). – Nick Bedford Nov 02 '11 at 01:23
-
1Sometimes an object is just never going to be null (or ReSharper thinks that is the case) IQueryable object pulling data when say you know that the query is not going to pull any records, it still is not going to be "null" Just have to refactor your code to not make ReSharper unhappy as it is correct possibly a larger % of the time over most developers. – Tom Stickel Oct 22 '15 at 05:09
8
Here's an example of ReSharper giving the cryptic "Heuristically unreachable code" warning:
It's an example of:
- ReSharper being way too smart for itself, because if you remove it the compiler will complain about a lack of a return statement
- Use of a word that is not common lexicon
1
Say you're deleting 2 different kinds of objects in a unit test and you want to use a try/catch for both types.
If you delete one, and then check to see if it was successful without properly casting using:
Assert.IsNull(obj1);
The "IsNull" may always be null because you casted obj1 incorrectly, or did something above the greyed out code incorrectly with obj1, the next try/catch will be greyed out.
Try fixing the thing you're trying to Assert.IsNull and once it's not always null or undefined, the greyed out code will be reachable.

whyoz
- 5,168
- 47
- 53