Skip to content

Commit 133b369

Browse files
committed
fixes Declaration.IsObject implementation / edge-case false positives for ObjectReferenceNotSet
1 parent 8a8fe88 commit 133b369

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

Rubberduck.Parsing/Symbols/Declaration.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,24 @@ private static string CorrectlyFormatedDescription(string literalDescription)
349349
/// </summary>
350350
public bool IsEnumeratorMember => _attributes.Any(a => a.Name.EndsWith("VB_UserMemId") && a.Values.Contains("-4"));
351351

352-
public virtual bool IsObject =>
353-
AsTypeName == Tokens.Object || (
354-
AsTypeDeclaration?.DeclarationType.HasFlag(DeclarationType.ClassModule) ??
355-
!AsTypeIsBaseType
356-
&& !IsArray
357-
&& !DeclarationType.HasFlag(DeclarationType.UserDefinedType)
358-
&& !DeclarationType.HasFlag(DeclarationType.Enumeration));
352+
public virtual bool IsObject
353+
{
354+
get
355+
{
356+
if (AsTypeName == Tokens.Object ||
357+
(AsTypeDeclaration?.DeclarationType.HasFlag(DeclarationType.ClassModule) ?? false))
358+
{
359+
return true;
360+
}
361+
362+
var result = !(AsTypeIsBaseType ||
363+
IsArray ||
364+
DeclarationType.HasFlag(DeclarationType.UserDefinedType) ||
365+
DeclarationType.HasFlag(DeclarationType.Enumeration));
366+
367+
return result;
368+
}
369+
}
359370

360371
public void AddReference(
361372
QualifiedModuleName module,

Rubberduck.Parsing/Symbols/PropertyDeclaration.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ protected PropertyDeclaration(
4444
attributes)
4545
{ }
4646

47-
public override bool IsObject =>
48-
base.IsObject || (Parameters.OrderBy(p => p.Selection).LastOrDefault()?.IsObject ?? false);
47+
public override bool IsObject
48+
{
49+
get
50+
{
51+
if (base.IsObject)
52+
{
53+
return true;
54+
}
55+
56+
return (DeclarationType == DeclarationType.PropertyLet ||
57+
DeclarationType == DeclarationType.PropertySet) &&
58+
(Parameters.OrderBy(p => p.Selection).LastOrDefault()?.IsObject ?? false);
59+
}
60+
}
4961

5062
/// <inheritdoc/>
5163
protected abstract override bool Implements(IInterfaceExposable member);

RubberduckTests/Inspections/ObjectVariableNotSetInspectionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class ObjectVariableNotSetInspectionTests
1313
{
1414
[Test]
1515
[Category("Inspections")]
16-
public void ObjectVariableNotSet_NotResultForBoolean()
16+
public void ObjectVariableNotSet_NotResultForNonObjectPropertyGetWithObjectArgument()
1717
{
1818
var expectedResultCount = 0;
1919
var input = @"
20-
Public Property Get Something() As Boolean
21-
Something = True
20+
Public Property Get Foo(ByVal bar As Object) As Boolean
21+
Foo = True
2222
End Property
2323
";
2424
AssertInputCodeYieldsExpectedInspectionResultCount(input, expectedResultCount);

0 commit comments

Comments
 (0)