@@ -72,6 +72,7 @@ public static bool RequiresSetAssignment(IdentifierReference reference, IDeclara
72
72
if ( expression == null )
73
73
{
74
74
Debug . Assert ( false , "RHS expression is empty? What's going on here?" ) ;
75
+ return false ;
75
76
}
76
77
77
78
if ( expression is VBAParser . NewExprContext )
@@ -86,25 +87,30 @@ public static bool RequiresSetAssignment(IdentifierReference reference, IDeclara
86
87
// RHS is a 'Nothing' token - LHS needs a 'Set' keyword:
87
88
return true ;
88
89
}
90
+ if ( literalExpression != null )
91
+ {
92
+ return false ; // any other literal expression definitely isn't an object.
93
+ }
89
94
90
95
// todo resolve expression return type
91
96
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
+ //}
103
109
104
110
// is the reference referring to something else in scope that's a object?
105
111
var project = Declaration . GetProjectParent ( reference . ParentScoping ) ;
106
112
var module = Declaration . GetModuleParent ( reference . ParentScoping ) ;
107
- return declarationFinderProvider . DeclarationFinder . MatchName ( expression . GetText ( ) . ToLowerInvariant ( ) )
113
+ return declarationFinderProvider . DeclarationFinder . MatchName ( expression . GetText ( ) )
108
114
. Any ( decl => ( decl . DeclarationType . HasFlag ( DeclarationType . ClassModule ) || Tokens . Object . Equals ( decl . AsTypeName ) )
109
115
&& AccessibilityCheck . IsAccessible ( project , module , reference . ParentScoping , decl ) ) ;
110
116
}
0 commit comments