Skip to content

Commit 4ace3ae

Browse files
authored
Merge pull request #1847 from Hosch250/Issue1845
Fix Implicit Reference to Active Sheet Inspection
2 parents 20c1ab7 + 6537713 commit 4ace3ae

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

RetailCoder.VBE/Inspections/ImplicitActiveSheetReferenceInspection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3636
}
3737

3838
var matches = BuiltInDeclarations.Where(item =>
39-
Targets.Contains(item.IdentifierName)).ToList();
39+
Targets.Contains(item.IdentifierName) &&
40+
item.ParentScope == "EXCEL.EXE;Excel._Global" &&
41+
item.AsTypeName == "Range").ToList();
4042

4143
var issues = matches.Where(item => item.References.Any())
4244
.SelectMany(declaration => declaration.References);

Rubberduck.Parsing/Symbols/ClassModuleDeclaration.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ public bool IsGlobalClassModule
104104
attributeIsGlobalClassModule = value.Single() == "True";
105105
}
106106
_isGlobal = attributeIsGlobalClassModule;
107+
108+
if (!_isGlobal.Value)
109+
{
110+
foreach (var type in Subtypes)
111+
{
112+
if (type is ClassModuleDeclaration && ((ClassModuleDeclaration) type).IsGlobalClassModule)
113+
{
114+
_isGlobal = true;
115+
break;
116+
}
117+
}
118+
}
119+
107120
return _isGlobal.Value;
108121
}
109122
}

Rubberduck.Parsing/Symbols/ReferencedDeclarationsCollector.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ public List<Declaration> GetDeclarationsForReference(Reference reference)
207207
attributes.AddPredeclaredIdTypeAttribute();
208208
}
209209

210+
if (typeAttributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FAPPOBJECT))
211+
{
212+
attributes.AddGlobalClassAttribute();
213+
}
214+
210215
Declaration moduleDeclaration;
211216
switch (typeDeclarationType)
212217
{

Rubberduck.Parsing/VBA/Attributes.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ public void AddPredeclaredIdTypeAttribute()
3939
{
4040
Add("VB_PredeclaredId", new[] {"True"});
4141
}
42+
43+
public void AddGlobalClassAttribute()
44+
{
45+
Add("VB_GlobalNamespace", new[] {"True"});
46+
}
4247
}
4348
}

0 commit comments

Comments
 (0)