Skip to content

Commit 6c70467

Browse files
committed
Deal with missing arguments when resolving argument references
1 parent fe40c67 commit 6c70467

File tree

12 files changed

+104
-3
lines changed

12 files changed

+104
-3
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/ArgumentWithIncompatibleObjectTypeInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ private static bool ToBeConsidered(Declaration declaration)
127127

128128
private string ArgumentSetTypeName(IdentifierReference argumentReference, DeclarationFinder finder)
129129
{
130-
return SetTypeNameOfExpression((VBAParser.ExpressionContext)argumentReference.Context, argumentReference.QualifiedModuleName, finder);
130+
var argumentExpression = argumentReference.Context as VBAParser.ExpressionContext;
131+
return SetTypeNameOfExpression(argumentExpression, argumentReference.QualifiedModuleName, finder);
131132
}
132133

133134
private string SetTypeNameOfExpression(VBAParser.ExpressionContext expression, QualifiedModuleName containingModule, DeclarationFinder finder)

Rubberduck.Parsing/Binding/ArgumentListArgument.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void Resolve(Declaration calledProcedure, int parameterIndex, bool isArra
4242
ReferencedParameter = ResolveReferencedParameter(calledProcedure, parameterIndex);
4343

4444
if (!_isAddressOfArgument
45+
&& !(Context is VBAParser.MissingArgumentContext)
4546
&& (isArrayAccess
4647
|| ReferencedParameter != null
4748
&& !CanBeObject(ReferencedParameter)))

Rubberduck.Parsing/Binding/ArgumentListArgumentType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public enum ArgumentListArgumentType
44
{
55
Positional,
6-
Named
6+
Named,
7+
Missing
78
}
89
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Antlr4.Runtime;
2+
using Rubberduck.Parsing.Symbols;
3+
4+
namespace Rubberduck.Parsing.Binding
5+
{
6+
public sealed class MissingArgumentBinding : IExpressionBinding
7+
{
8+
private readonly Declaration _parent;
9+
private readonly ParserRuleContext _missingArgumentContext;
10+
11+
public MissingArgumentBinding(ParserRuleContext missingArgumentContext)
12+
{
13+
_missingArgumentContext = missingArgumentContext;
14+
}
15+
16+
public IBoundExpression Resolve()
17+
{
18+
return new MissingArgumentExpression(ExpressionClassification.Variable, _missingArgumentContext);
19+
}
20+
}
21+
}

Rubberduck.Parsing/Binding/DefaultBindingContext.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ private ArgumentList VisitArgumentList(Declaration module, Declaration parent, V
255255
CreateNamedArgumentExpressionCreator(expr.namedArgument().unrestrictedIdentifier().GetText(), expr.namedArgument().unrestrictedIdentifier()),
256256
isAddressOfArgument));
257257
}
258+
else if(expr.missingArgument() != null)
259+
{
260+
var missingArgumentContext = expr.missingArgument();
261+
var binding = new MissingArgumentBinding(missingArgumentContext);
262+
convertedList.AddArgument(new ArgumentListArgument(
263+
binding,
264+
missingArgumentContext,
265+
ArgumentListArgumentType.Missing,
266+
false));
267+
}
258268
}
259269
}
260270
return convertedList;

Rubberduck.Parsing/Binding/Expressions/DictionaryAccessExpression.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Antlr4.Runtime;
2-
using Rubberduck.Parsing.Grammar;
32
using Rubberduck.Parsing.Symbols;
43

54
namespace Rubberduck.Parsing.Binding
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Antlr4.Runtime;
2+
3+
namespace Rubberduck.Parsing.Binding
4+
{
5+
public sealed class MissingArgumentExpression : BoundExpression
6+
{
7+
public MissingArgumentExpression(
8+
ExpressionClassification classification,
9+
ParserRuleContext context)
10+
: base(null, classification, context)
11+
{}
12+
}
13+
}

Rubberduck.Parsing/TypeResolvers/SetTypeResolver.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public SetTypeResolver(IDeclarationFinderProvider declarationFinderProvider)
2222

2323
public Declaration SetTypeDeclaration(VBAParser.ExpressionContext expression, QualifiedModuleName containingModule)
2424
{
25+
if (expression == null)
26+
{
27+
return null;
28+
}
29+
2530
switch (expression)
2631
{
2732
case VBAParser.LExprContext lExpression:
@@ -53,6 +58,11 @@ private Declaration SetTypeDeclaration(Declaration setTypeDeterminingDeclaration
5358

5459
public string SetTypeName(VBAParser.ExpressionContext expression, QualifiedModuleName containingModule)
5560
{
61+
if (expression == null)
62+
{
63+
return null;
64+
}
65+
5666
switch (expression)
5767
{
5868
case VBAParser.LExprContext lExpression:

Rubberduck.Parsing/VBA/ReferenceManagement/BoundExpressionVisitor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ private void Visit(
8787
case ProcedureCoercionExpression procedureCoercionExpression:
8888
Visit(procedureCoercionExpression, module, scope, parent);
8989
break;
90+
case MissingArgumentExpression missingArgumentExpression:
91+
break;
9092
default:
9193
throw new NotSupportedException($"Unexpected bound expression type {boundExpression.GetType()}");
9294
}

Rubberduck.Parsing/VBA/ReferenceManagement/FailedResolutionVisitor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ private void Visit(IBoundExpression boundExpression, Declaration parent, IBoundE
7070
case ProcedureCoercionExpression procedureCoercionExpression:
7171
Visit(procedureCoercionExpression, parent, withExpression);
7272
break;
73+
case MissingArgumentExpression missingArgumentExpression:
74+
break;
7375
default:
7476
throw new NotSupportedException($"Unexpected bound expression type {boundExpression.GetType()}");
7577
}

0 commit comments

Comments
 (0)