Skip to content

Commit b0e6d66

Browse files
committed
ref. #4037
1 parent ade4fee commit b0e6d66

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/VariableRequiresSetAssignmentEvaluator.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,17 @@ public static bool RequiresSetAssignment(IdentifierReference reference, IDeclara
9393
}
9494

9595
// todo resolve expression return type
96+
var project = Declaration.GetProjectParent(reference.ParentScoping);
97+
var module = Declaration.GetModuleParent(reference.ParentScoping);
9698

97-
98-
//var memberRefs = declarationFinderProvider.DeclarationFinder.IdentifierReferences(reference.ParentScoping.QualifiedName);
99-
//var lastRef = memberRefs.LastOrDefault(r => r.IsAssignment && !Equals(r, reference) && r.Context.GetAncestor<VBAParser.LetStmtContext>() == letStmtContext);
100-
//if (lastRef?.Declaration.AsTypeDeclaration?.DeclarationType.HasFlag(DeclarationType.ClassModule) ?? false)
101-
//{
102-
// // the last reference in the expression is referring to an object type
103-
// return true;
104-
//}
105-
//if (lastRef?.Declaration.AsTypeName == Tokens.Object)
106-
//{
107-
// return true;
108-
//}
99+
var simpleName = expression.GetDescendent<VBAParser.SimpleNameExprContext>();
100+
if (simpleName != null)
101+
{
102+
return declarationFinderProvider.DeclarationFinder.MatchName(simpleName.identifier().GetText())
103+
.Any(d => AccessibilityCheck.IsAccessible(project, module, reference.ParentScoping, d) && d.IsObject);
104+
}
109105

110106
// is the reference referring to something else in scope that's a object?
111-
var project = Declaration.GetProjectParent(reference.ParentScoping);
112-
var module = Declaration.GetModuleParent(reference.ParentScoping);
113107
return declarationFinderProvider.DeclarationFinder.MatchName(expression.GetText())
114108
.Any(decl => (decl.DeclarationType.HasFlag(DeclarationType.ClassModule) || Tokens.Object.Equals(decl.AsTypeName))
115109
&& AccessibilityCheck.IsAccessible(project, module, reference.ParentScoping, decl));

RubberduckTests/Inspections/ObjectVariableNotSetInspectionTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void ObjectVariableNotSet_GivenVariantVariableAssignedRange_ReturnsResult
163163
var input =
164164
@"
165165
Private Sub TestSub(ByRef testParam As Variant)
166-
testParam = Range(""A1:C1"")
166+
testParam = Range(""A1:C1"")
167167
End Sub";
168168
AssertInputCodeYieldsExpectedInspectionResultCount(input, expectResultCount, "Excel.1.8.xml");
169169
}
@@ -196,7 +196,6 @@ Dim target As Variant
196196
}
197197

198198
[Test]
199-
[Ignore("Broken by COM collector fix, is failing case for default member resolution. See #4037")]
200199
[Category("Inspections")]
201200
public void ObjectVariableNotSet_GivenObjectVariableNotSet_ReturnsResult()
202201
{
@@ -215,7 +214,6 @@ Dim target As Range
215214
}
216215

217216
[Test]
218-
[Ignore("Broken by COM collector fix, is failing case for default member resolution. See #4037")]
219217
[Category("Inspections")]
220218
public void ObjectVariableNotSet_GivenObjectVariableNotSet_Ignored_DoesNotReturnResult()
221219
{
@@ -235,7 +233,6 @@ Dim target As Range
235233
}
236234

237235
[Test]
238-
[Ignore("Broken by COM collector fix, is failing case for default member resolution. See #4037")]
239236
[Category("Inspections")]
240237
public void ObjectVariableNotSet_GivenSetObjectVariable_ReturnsNoResult()
241238
{

0 commit comments

Comments
 (0)