Skip to content

Commit 617e56d

Browse files
committed
Fix UnreachableCaseInspection
There was an NRE in case a context is null. Only the corresponding method has been rewritten. A full review will have to wait until later.
1 parent 9c3643f commit 617e56d

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/UnreachableCaseInspection/UnreachableCaseInspection.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,22 @@ public static IParseTreeValueVisitor CreateParseTreeValueVisitor(IParseTreeValue
198198
}
199199

200200
//public static to support tests
201-
public static (bool success, IdentifierReference idRef) GetIdentifierReferenceForContext(ParserRuleContext context, RubberduckParserState state)
201+
public static (bool success, IdentifierReference idRef) GetIdentifierReferenceForContext(ParserRuleContext context, IDeclarationFinderProvider declarationFinderProvider)
202202
{
203-
IdentifierReference idRef = null;
204-
var success = false;
205-
var identifierReferences = (state.DeclarationFinder.MatchName(context.GetText()).Select(dec => dec.References)).SelectMany(rf => rf)
206-
.Where(rf => rf.Context == context);
207-
if (identifierReferences.Count() == 1)
203+
if (context == null)
208204
{
209-
idRef = identifierReferences.First();
210-
success = true;
205+
return (false, null);
211206
}
212-
return (success, idRef);
207+
208+
var finder = declarationFinderProvider.DeclarationFinder;
209+
var identifierReferences = finder.MatchName(context.GetText())
210+
.SelectMany(declaration => declaration.References)
211+
.Where(reference => reference.Context == context)
212+
.ToList();
213+
214+
return identifierReferences.Count == 1
215+
? (true, identifierReferences.First())
216+
: (false, null);
213217
}
214218

215219
//Method is used as a delegate to avoid propogating RubberduckParserState beyond this class

0 commit comments

Comments
 (0)