Skip to content

Commit ade4fee

Browse files
committed
fixes #4318;
1 parent 8ec9af9 commit ade4fee

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/VariableRequiresSetAssignmentEvaluator.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static bool RequiresSetAssignment(IdentifierReference reference, IDeclara
7272
if (expression == null)
7373
{
7474
Debug.Assert(false, "RHS expression is empty? What's going on here?");
75+
return false;
7576
}
7677

7778
if (expression is VBAParser.NewExprContext)
@@ -86,25 +87,30 @@ public static bool RequiresSetAssignment(IdentifierReference reference, IDeclara
8687
// RHS is a 'Nothing' token - LHS needs a 'Set' keyword:
8788
return true;
8889
}
90+
if (literalExpression != null)
91+
{
92+
return false; // any other literal expression definitely isn't an object.
93+
}
8994

9095
// todo resolve expression return type
9196

92-
var memberRefs = declarationFinderProvider.DeclarationFinder.IdentifierReferences(reference.ParentScoping.QualifiedName);
93-
var lastRef = memberRefs.LastOrDefault(r => !Equals(r, reference) && r.Context.GetAncestor<VBAParser.LetStmtContext>() == letStmtContext);
94-
if (lastRef?.Declaration.AsTypeDeclaration?.DeclarationType.HasFlag(DeclarationType.ClassModule) ?? false)
95-
{
96-
// the last reference in the expression is referring to an object type
97-
return true;
98-
}
99-
if (lastRef?.Declaration.AsTypeName == Tokens.Object)
100-
{
101-
return true;
102-
}
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+
//}
103109

104110
// is the reference referring to something else in scope that's a object?
105111
var project = Declaration.GetProjectParent(reference.ParentScoping);
106112
var module = Declaration.GetModuleParent(reference.ParentScoping);
107-
return declarationFinderProvider.DeclarationFinder.MatchName(expression.GetText().ToLowerInvariant())
113+
return declarationFinderProvider.DeclarationFinder.MatchName(expression.GetText())
108114
.Any(decl => (decl.DeclarationType.HasFlag(DeclarationType.ClassModule) || Tokens.Object.Equals(decl.AsTypeName))
109115
&& AccessibilityCheck.IsAccessible(project, module, reference.ParentScoping, decl));
110116
}

0 commit comments

Comments
 (0)