Skip to content

Commit 91ed30e

Browse files
committed
Fix missing default member result for optional parentheses on properties
The problem was that the empty argument list gets parsed as an argument list with a single missing argument and the IndexDefaultBinding did not account for it. Since the missing argument is actually a valid way to parse the empty argument list and the parser cannot know whether there is an optional parameter or not, I chose to catch this in the IndexDefaultBinding.
1 parent 136889f commit 91ed30e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Rubberduck.Parsing/Binding/Bindings/IndexDefaultBinding.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,11 @@ declared type.
356356
private static bool ArgumentListIsCompatible(ICollection<ParameterDeclaration> parameters, ArgumentList argumentList)
357357
{
358358
return (parameters.Count >= (argumentList?.Arguments.Count ?? 0)
359-
|| parameters.Any(parameter => parameter.IsParamArray))
360-
&& parameters.Count(parameter => !parameter.IsOptional && !parameter.IsParamArray) <= (argumentList?.Arguments.Count ?? 0);
359+
|| parameters.Any(parameter => parameter.IsParamArray))
360+
&& parameters.Count(parameter => !parameter.IsOptional && !parameter.IsParamArray) <= (argumentList?.Arguments.Count ?? 0)
361+
|| parameters.Count == 0
362+
&& argumentList?.Arguments.Count == 1
363+
&& argumentList.Arguments.Single().ArgumentType == ArgumentListArgumentType.Missing;
361364
}
362365

363366
private IBoundExpression ResolveRecursiveDefaultMember(Declaration defaultMember, ExpressionClassification defaultMemberClassification, ArgumentList argumentList, ParserRuleContext expression, Declaration parent, int defaultMemberResolutionRecursionDepth, RecursiveDefaultMemberAccessExpression containedExpression)

RubberduckTests/Inspections/DefaultMemberRequiredInspectionTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,31 @@ End Function
330330
Assert.AreEqual(expectedSelection, actualSelection);
331331
}
332332

333+
[Category("Inspections")]
334+
[Test]
335+
public void OptionalParenthesesAfterVariantReturningProperty_NoResult()
336+
{
337+
var classCode = @"
338+
Public Property Get Foo() As Variant
339+
End Property
340+
";
341+
342+
var moduleCode = @"
343+
Private Function Bar() As String
344+
Dim cls As new Class1
345+
Bar = cls.Foo()
346+
End Function
347+
";
348+
349+
var vbe = MockVbeBuilder.BuildFromModules(
350+
("Class1", classCode, ComponentType.ClassModule),
351+
("Module1", moduleCode, ComponentType.StandardModule));
352+
353+
var inspectionResults = InspectionResults(vbe.Object);
354+
355+
Assert.AreEqual(0, inspectionResults.Count());
356+
}
357+
333358
[Category("Inspections")]
334359
[Test]
335360
public void FailedIndexExpressionOnFunctionWithParameters_NoResult()

0 commit comments

Comments
 (0)