1
1
using System . Collections . Generic ;
2
2
using System . Linq ;
3
- using Rubberduck . Common ;
4
3
using Rubberduck . Inspections . Abstract ;
5
4
using Rubberduck . Inspections . Resources ;
6
5
using Rubberduck . Inspections . Results ;
@@ -44,7 +43,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
44
43
! item . IsSelfAssigned &&
45
44
! item . IsArray &&
46
45
! ValueTypes . Contains ( item . AsTypeName ) &&
47
- ( item . AsTypeDeclaration == null || (
46
+ ( item . AsTypeDeclaration == null || ( ! IsBuiltInTypeWithDefaultMember ( item . AsTypeDeclaration ) &&
48
47
item . AsTypeDeclaration . DeclarationType != DeclarationType . Enumeration &&
49
48
item . AsTypeDeclaration . DeclarationType != DeclarationType . UserDefinedType ) ) &&
50
49
( item . DeclarationType == DeclarationType . Variable ||
@@ -57,7 +56,9 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
57
56
&& item . IsTypeSpecified
58
57
&& ! ValueTypes . Contains ( item . AsTypeName )
59
58
&& ( 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 ) ) ) ) ;
61
62
62
63
var interestingReferences = interestingDeclarations
63
64
. Union ( interestingMembers . SelectMany ( item =>
@@ -66,13 +67,19 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
66
67
. SelectMany ( declaration =>
67
68
declaration . References . Where ( reference =>
68
69
{
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 ;
71
72
} )
72
73
) ;
73
74
74
75
75
76
return interestingReferences . Select ( reference => new ObjectVariableNotSetInspectionResult ( this , reference ) ) ;
76
77
}
78
+
79
+ private bool IsBuiltInTypeWithDefaultMember ( Declaration asType )
80
+ {
81
+ var classModule = asType as ClassModuleDeclaration ;
82
+ return classModule != null && asType . IsBuiltIn && classModule . DefaultMember != null ;
83
+ }
77
84
}
78
85
}
0 commit comments