Skip to content

Commit 93cf16b

Browse files
committed
Immediately fail the resolution of a with member access without a with expression
This prevents an otherwise guaranteed NRE in the MemberAccessBinding and lets us resolve everything else instead of outright stopping resolution because of the unexpected NRE.
1 parent d3a66b4 commit 93cf16b

File tree

5 files changed

+8
-17
lines changed

5 files changed

+8
-17
lines changed

Rubberduck.Parsing/Binding/Bindings/LetCoercionDefaultBinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private static IBoundExpression ResolveViaDefaultMember(IBoundExpression wrapped
114114
&& defaultMember.DeclarationType == DeclarationType.PropertyLet
115115
&& IsCompatibleWithOneNonObjectParameter(parameters))
116116
{
117-
//This is a Let assignment. So, finding a Property Let with one non object paramter means we are done.
117+
//This is a Let assignment. So, finding a Property Let with one non object parameter means we are done.
118118
return new LetCoercionDefaultMemberAccessExpression(defaultMember, defaultMemberClassification, expression, wrappedExpression, recursionDepth, containedExpression);
119119
}
120120

Rubberduck.Parsing/Binding/Bindings/NewTypeBinding.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
using Antlr4.Runtime;
2-
using Rubberduck.Parsing.Symbols;
3-
using Rubberduck.Parsing.VBA.DeclarationCaching;
42

53
namespace Rubberduck.Parsing.Binding
64
{
75
public sealed class NewTypeBinding : IExpressionBinding
86
{
9-
private readonly DeclarationFinder _declarationFinder;
10-
private readonly Declaration _project;
11-
private readonly Declaration _module;
12-
private readonly Declaration _parent;
137
private readonly ParserRuleContext _expression;
148
private readonly IExpressionBinding _typeExpressionBinding;
159

1610
public NewTypeBinding(
17-
DeclarationFinder declarationFinder,
18-
Declaration module,
19-
Declaration parent,
2011
ParserRuleContext expression,
2112
IExpressionBinding typeExpressionBinding)
2213
{
23-
_declarationFinder = declarationFinder;
24-
_project = module.ParentDeclaration;
25-
_module = module;
26-
_parent = parent;
2714
_expression = expression;
2815
_typeExpressionBinding = typeExpressionBinding;
2916
}

Rubberduck.Parsing/Binding/DefaultBindingContext.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private IExpressionBinding Visit(Declaration module, Declaration parent, VBAPars
198198
{
199199
return null;
200200
}
201-
return new NewTypeBinding(_declarationFinder, module, parent, expression, typeExpressionBinding);
201+
return new NewTypeBinding(expression, typeExpressionBinding);
202202
}
203203

204204
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.MarkedFileNumberExprContext expression, IBoundExpression withBlockVariable)
@@ -442,6 +442,10 @@ declared type of String and a value equal to the name value of <unrestricted-nam
442442

443443
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.WithMemberAccessExprContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext)
444444
{
445+
if (withBlockVariable == null)
446+
{
447+
withBlockVariable = new ResolutionFailedExpression(expression);
448+
}
445449
return new MemberAccessDefaultBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression, withBlockVariable, expression.unrestrictedIdentifier().GetText(), statementContext, expression.unrestrictedIdentifier());
446450
}
447451

Rubberduck.Parsing/VBA/DeclarationCaching/DeclarationFinder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,8 @@ public void AddUnboundContext(Declaration parentDeclaration, VBAParser.LExpressi
10021002
{
10031003

10041004
//The only forms we care about right now are MemberAccessExprContext or WithMemberAccessExprContext.
1005-
if (!(context is VBAParser.MemberAccessExprContext) && !(context is VBAParser.WithMemberAccessExprContext))
1005+
//For WithMemberAccessExpressions we can only save an unbout member if the withExpression is not null.
1006+
if (!(context is VBAParser.MemberAccessExprContext) && !(context is VBAParser.WithMemberAccessExprContext && withExpression != null))
10061007
{
10071008
return;
10081009
}

Rubberduck.Parsing/VBA/ReferenceManagement/IdentifierReferenceResolver.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public void EnterWithBlock(VBAParser.WithStmtContext context)
8282
false);
8383
_failedResolutionVisitor.CollectUnresolved(boundExpression, _currentParent, withExpression);
8484
_boundExpressionVisitor.AddIdentifierReferences(boundExpression, _qualifiedModuleName, _currentScope, _currentParent);
85-
// note: pushes null if unresolved
8685
_withBlockExpressions.Push(boundExpression);
8786
}
8887

0 commit comments

Comments
 (0)