Skip to content

Commit 8d28627

Browse files
committed
fixed issue with resolution of member calls in With block, where an extra reference was added to the type of the referenced local variable.
1 parent e777d74 commit 8d28627

File tree

1 file changed

+7
-40
lines changed

1 file changed

+7
-40
lines changed

Rubberduck.Parsing/Symbols/IdentifierReferenceResolver.cs

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public void EnterWithBlock(VBAParser.WithStmtContext context)
8282
if (context.NEW() == null)
8383
{
8484
// with block is using an identifier declared elsewhere.
85-
qualifier = ResolveType(context.implicitCallStmt_InStmt());
86-
reference = CreateReference(context.implicitCallStmt_InStmt(), qualifier);
85+
var callee = ResolveInternal(context.implicitCallStmt_InStmt(), _currentScope, ContextAccessorType.GetValueOrReference);
86+
qualifier = ResolveType(callee);
8787
}
8888
else
8989
{
@@ -106,11 +106,10 @@ public void EnterWithBlock(VBAParser.WithStmtContext context)
106106
else
107107
{
108108
qualifier = ResolveType(typeContext.complexType());
109-
reference = CreateReference(typeContext.complexType(), qualifier);
110109
}
111110
}
112111

113-
if (qualifier != null)
112+
if (qualifier != null && reference != null)
114113
{
115114
qualifier.AddReference(reference);
116115
_alreadyResolved.Add(reference.Context);
@@ -179,28 +178,6 @@ private Declaration ResolveType(VBAParser.ComplexTypeContext context)
179178
return null;
180179
}
181180

182-
private Declaration ResolveType(VBAParser.ImplicitCallStmt_InStmtContext context, Declaration localScope = null)
183-
{
184-
if (context == null)
185-
{
186-
return null;
187-
}
188-
189-
if (localScope == null)
190-
{
191-
localScope = _currentScope;
192-
}
193-
194-
var dictionaryCall = context.iCS_S_DictionaryCall();
195-
196-
var type = ResolveInternal(context.iCS_S_VariableOrProcedureCall(), localScope)
197-
?? ResolveInternal(context.iCS_S_ProcedureOrArrayCall(), localScope)
198-
?? ResolveInternal(context.iCS_S_MembersCall(), ContextAccessorType.GetValueOrReference)
199-
?? ResolveInternal(dictionaryCall, localScope, ContextAccessorType.GetValueOrReference, dictionaryCall == null ? null : dictionaryCall.dictionaryCallStmt());
200-
201-
return ResolveType(type);
202-
}
203-
204181
private Declaration ResolveType(Declaration parent)
205182
{
206183
if (parent == null || parent.AsTypeName == null)
@@ -258,7 +235,7 @@ private Declaration ResolveInternal(ParserRuleContext callSiteContext, Declarati
258235
{
259236
// localScope is probably a UDT
260237
var udt = ResolveType(localScope);
261-
if (udt != null)
238+
if (udt != null && udt.DeclarationType == DeclarationType.UserDefinedType)
262239
{
263240
callee = _declarations[identifierName].SingleOrDefault(item => item.Context != null && item.Context.Parent == udt.Context);
264241
}
@@ -381,16 +358,6 @@ private Declaration ResolveInternal(VBAParser.ICS_S_MembersCallContext context,
381358
parent = ResolveType(parent);
382359
}
383360

384-
if (parent != null)
385-
{
386-
var parentReference = CreateReference(parent.Context, parent);
387-
if (parentReference != null)
388-
{
389-
parent.AddReference(parentReference);
390-
_alreadyResolved.Add(parentReference.Context);
391-
}
392-
}
393-
394361
var chainedCalls = context.iCS_S_MemberCall();
395362
var lastCall = chainedCalls.Last();
396363
foreach (var memberCall in chainedCalls)
@@ -550,9 +517,9 @@ public void Resolve(VBAParser.ICS_S_MembersCallContext context)
550517
var notationToken = memberCall.children[0];
551518
if (notationToken.GetText() == "!")
552519
{
553-
// we can't handle this syntax yet.
554-
// we need to know what the parent's default property is..
555-
// ...and whether it has a parameterized getter taking in a string.
520+
// the memberCall is a shorthand reference to the type's default member.
521+
// since the reference isn't explicit, we don't need to care for it.
522+
// (and we couldn't handle it if we wanted to, since we aren't parsing member attributes)
556523
return;
557524
}
558525

0 commit comments

Comments
 (0)