Skip to content

Commit 7dee010

Browse files
committed
fixes #2228 ...that was so trivial it's scary
1 parent 7b12e6d commit 7dee010

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

RetailCoder.VBE/Inspections/UnassignedVariableUsageInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3131
var lenbFunction = BuiltInDeclarations.SingleOrDefault(s => s.Scope == "VBE7.DLL;VBA.Strings.LenB");
3232

3333
return from issue in declarations
34-
where !DeclarationReferencesContainsReference(lenFunction, issue)
34+
where issue.References.Any()
35+
&& !DeclarationReferencesContainsReference(lenFunction, issue)
3536
&& !DeclarationReferencesContainsReference(lenbFunction, issue)
3637
select new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedName.QualifiedModuleName, issue);
3738
}

RubberduckTests/Inspections/UnassignedVariableUsageInspectionTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,34 @@ Dim bb As Boolean
155155
Assert.IsFalse(inspectionResults.Any());
156156
}
157157

158+
[TestMethod]
159+
public void UnassignedVariableUsage_NoResultIfNoReferences()
160+
{
161+
const string inputCode =
162+
@"Sub DoSomething()
163+
Dim foo
164+
End Sub";
165+
166+
//Arrange
167+
var builder = new MockVbeBuilder();
168+
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
169+
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
170+
.Build();
171+
var vbe = builder.AddProject(project).Build();
172+
173+
var mockHost = new Mock<IHostApplication>();
174+
mockHost.SetupAllProperties();
175+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock<ISinks>().Object));
176+
177+
parser.Parse(new CancellationTokenSource());
178+
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
179+
180+
var inspection = new UnassignedVariableUsageInspection(parser.State);
181+
var inspectionResults = inspection.GetInspectionResults();
182+
183+
Assert.IsFalse(inspectionResults.Any());
184+
}
185+
158186
// Ignored until we can reinstate the quick fix on a specific reference
159187
// [TestMethod]
160188
// [TestCategory("Inspections")]

0 commit comments

Comments
 (0)