Skip to content

Commit 8ac381c

Browse files
committed
Fixes newly discovered bugs
1 parent 5f61263 commit 8ac381c

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/ParseTreeValueVisitor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ private void GetContextValue(ParserRuleContext context, out string declaredTypeN
279279
private bool TryGetIdentifierReferenceForContext(ParserRuleContext context, out IdentifierReference idRef)
280280
{
281281
idRef = null;
282-
var nameToMatch = context.GetText();
283-
var identifierReferences = (_state.DeclarationFinder.MatchName(context.GetText()).Select(dec => dec.References)).SelectMany(rf => rf);
284-
if (identifierReferences.Any(rf => rf.Context == context))
282+
var identifierReferences = (_state.DeclarationFinder.MatchName(context.GetText()).Select(dec => dec.References)).SelectMany(rf => rf)
283+
.Where(rf => rf.Context == context);
284+
if (identifierReferences.Count() == 1)
285285
{
286286
idRef = identifierReferences.First();
287287
return true;

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/RangeClauseFilter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ public void Add(IRangeClauseFilter filter)
156156
{
157157
AddSingleValueImpl(val);
158158
}
159+
160+
foreach (var val in newFilter.VariableSingleValues)
161+
{
162+
VariableSingleValues.Add(val);
163+
}
159164
_descriptorIsDirty = true;
160165
}
161166

Rubberduck.Inspections/Concrete/UnreachableCaseInspection/UnreachableCaseInspection.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public sealed class UnreachableCaseInspection : ParseTreeInspectionBase
1818
private IParseTreeValueVisitorFactory _parseTreeVisitorFactory;
1919
private ISelectCaseStmtContextWrapperFactory _selectStmtFactory;
2020
private IParseTreeValueFactory _valueFactory;
21-
private IParseTreeValueVisitor _parseTreeValueVisitor;
2221
private enum CaseInpectionResult { Unreachable, MismatchType, CaseElse };
2322

2423
private static Dictionary<CaseInpectionResult, string> ResultMessages = new Dictionary<CaseInpectionResult, string>()
@@ -36,16 +35,14 @@ public UnreachableCaseInspection(RubberduckParserState state) : base(state)
3635
_selectStmtFactory = factoriesFactory.CreateISelectStmtContextWrapperFactory();
3736
_valueFactory = factoriesFactory.CreateIParseTreeValueFactory();
3837
_parseTreeVisitorFactory = factoriesFactory.CreateIParseTreeValueVisitorFactory();
39-
40-
_parseTreeValueVisitor = _parseTreeVisitorFactory.Create(State, _valueFactory);
4138
}
4239

4340
public override IInspectionListener Listener { get; } =
4441
new UnreachableCaseInspectionListener();
4542

4643
private List<IInspectionResult> InspectionResults { set; get; } = new List<IInspectionResult>();
4744

48-
private ParseTreeVisitorResults ValueResults { get; } = new ParseTreeVisitorResults();
45+
private ParseTreeVisitorResults ValueResults { set; get; } = new ParseTreeVisitorResults();
4946

5047
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
5148
{
@@ -54,6 +51,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
5451
.Where(result => !IsIgnoringInspectionResultFor(result.ModuleName, result.Context.Start.Line));
5552

5653
var parseTreeValueVisitor = _parseTreeVisitorFactory.Create(State, _valueFactory);
54+
ValueResults = new ParseTreeVisitorResults();
5755
parseTreeValueVisitor.OnValueResultCreated += ValueResults.OnNewValueResult;
5856

5957
foreach (var qualifiedSelectCaseStmt in qualifiedSelectCaseStmts)

RubberduckTests/Inspections/UnreachableCaseInspectionTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ public void UciUnit_FilterBoolean(string firstCase, string secondCase, string ex
596596
Assert.AreEqual(expected, filteredResults);
597597
}
598598

599+
[TestCase("Range:3:55", "Single=x.Item(2)", "Range:3:55,Single=x.Item(2)")]
599600
[TestCase("Range=3:55", "IsLT=6", "IsLT=6,Range=6:55")]
600601
[TestCase("Range=3:55", "IsGT=6", "IsGT=6,Range=3:6")]
601602
[TestCase("IsLT=6", "Range=1:5", "IsLT=6")]
@@ -2544,6 +2545,38 @@ Public Const MY_CONSTANT As <propertyTypeAndAssignment>
25442545
CheckActualResultsEqualsExpected(components, unreachable: 1);
25452546
}
25462547

2548+
[Test]
2549+
[Category("Inspections")]
2550+
public void UciFunctional_DuplicateSelectExpressionVariableInModule()
2551+
{
2552+
string inputCode =
2553+
@"
2554+
Sub FirstSub(x As Long)
2555+
Select Case x
2556+
Case 55
2557+
MsgBox CStr(x)
2558+
Case 56
2559+
MsgBox CStr(x)
2560+
Case 55
2561+
MsgBox ""Unreachable""
2562+
End Select
2563+
End Sub
2564+
2565+
Sub SecondSub(x As Boolean)
2566+
Select Case x
2567+
Case 55
2568+
MsgBox CStr(x)
2569+
Case 0
2570+
MsgBox CStr(x)
2571+
Case Else
2572+
MsgBox ""Unreachable""
2573+
End Select
2574+
End Sub
2575+
";
2576+
2577+
CheckActualResultsEqualsExpected(inputCode, unreachable: 1, caseElse: 1);
2578+
}
2579+
25472580
private static void CheckActualResultsEqualsExpected(string inputCode, int unreachable = 0, int mismatch = 0, int caseElse = 0)
25482581
{
25492582
var components = new List<Tuple<string, string>>()

0 commit comments

Comments
 (0)