Skip to content

Commit 769f3ba

Browse files
committed
ObjectVariableNotSet ignores types with default members; fixes #1868
1 parent b337b77 commit 769f3ba

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

RetailCoder.VBE/Inspections/ObjectVariableNotSetInspection.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Rubberduck.Common;
43
using Rubberduck.Inspections.Abstract;
54
using Rubberduck.Inspections.Resources;
65
using Rubberduck.Inspections.Results;
@@ -44,7 +43,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
4443
!item.IsSelfAssigned &&
4544
!item.IsArray &&
4645
!ValueTypes.Contains(item.AsTypeName) &&
47-
(item.AsTypeDeclaration == null || (
46+
(item.AsTypeDeclaration == null || (!IsBuiltInTypeWithDefaultMember(item.AsTypeDeclaration) &&
4847
item.AsTypeDeclaration.DeclarationType != DeclarationType.Enumeration &&
4948
item.AsTypeDeclaration.DeclarationType != DeclarationType.UserDefinedType)) &&
5049
(item.DeclarationType == DeclarationType.Variable ||
@@ -57,7 +56,9 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
5756
&& item.IsTypeSpecified
5857
&& !ValueTypes.Contains(item.AsTypeName)
5958
&& (item.AsTypeDeclaration == null // null if unresolved (e.g. in unit tests)
60-
|| (item.AsTypeDeclaration.DeclarationType != DeclarationType.Enumeration && item.AsTypeDeclaration.DeclarationType != DeclarationType.UserDefinedType)));
59+
|| (item.AsTypeDeclaration.DeclarationType != DeclarationType.Enumeration && item.AsTypeDeclaration.DeclarationType != DeclarationType.UserDefinedType
60+
&& item.AsTypeDeclaration != null
61+
&& !IsBuiltInTypeWithDefaultMember(item.AsTypeDeclaration))));
6162

6263
var interestingReferences = interestingDeclarations
6364
.Union(interestingMembers.SelectMany(item =>
@@ -66,13 +67,19 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
6667
.SelectMany(declaration =>
6768
declaration.References.Where(reference =>
6869
{
69-
var setStmtContext = ParserRuleContextHelper.GetParent<VBAParser.LetStmtContext>(reference.Context);
70-
return reference.IsAssignment && setStmtContext != null && setStmtContext.LET() == null;
70+
var letStmtContext = ParserRuleContextHelper.GetParent<VBAParser.LetStmtContext>(reference.Context);
71+
return reference.IsAssignment && letStmtContext != null && letStmtContext.LET() == null;
7172
})
7273
);
7374

7475

7576
return interestingReferences.Select(reference => new ObjectVariableNotSetInspectionResult(this, reference));
7677
}
78+
79+
private bool IsBuiltInTypeWithDefaultMember(Declaration asType)
80+
{
81+
var classModule = asType as ClassModuleDeclaration;
82+
return classModule != null && asType.IsBuiltIn && classModule.DefaultMember != null;
83+
}
7784
}
7885
}

0 commit comments

Comments
 (0)