Skip to content

Commit a18c20f

Browse files
committed
fixed untyped function usage inspection and reference resolution
1 parent 768467f commit a18c20f

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public UntypedFunctionUsageInspection(RubberduckParserState state)
4545
public override IEnumerable<InspectionResultBase> GetInspectionResults()
4646
{
4747
var declarations = BuiltInDeclarations
48-
.Where(item => item.DeclarationType == DeclarationType.Function
49-
&& _tokens.Any(token => item.IdentifierName.EndsWith("_var_" + token)));
48+
// note: these *should* be functions, but somehow they're not defined as such
49+
.Where(item => _tokens.Any(token => item.IdentifierName == ("_B_var_" + token) && item.References.Any()));
5050

5151
return declarations.SelectMany(declaration => declaration.References
5252
.Select(item => new UntypedFunctionUsageInspectionResult(this, string.Format(Description, declaration.IdentifierName), item.QualifiedModuleName, item.Context)));

Rubberduck.Parsing/Symbols/DeclarationFinder.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,18 @@ public IEnumerable<Declaration> MatchName(string name)
5656
{
5757
return result;
5858
}
59-
59+
if (_declarationsByName.TryGetValue("_" + name, out result))
60+
{
61+
return result;
62+
}
63+
if (_declarationsByName.TryGetValue("I" + name, out result))
64+
{
65+
return result;
66+
}
67+
if (_declarationsByName.TryGetValue("_I" + name, out result))
68+
{
69+
return result;
70+
}
6071
return new List<Declaration>();
6172
}
6273

Rubberduck.Parsing/Symbols/IdentifierReferenceResolver.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,7 @@ private Declaration FindProjectScopeDeclaration(string identifierName, Declarati
10921092
{
10931093
// the "$" in e.g. "UCase$" isn't picked up as part of the identifierName, so we need to add it manually:
10941094
var matches = _declarationFinder.MatchName(identifierName).Where(item =>
1095-
(!item.IsBuiltIn || item.IdentifierName == identifierName + (hasStringQualifier ? "$" : string.Empty))
1096-
&& item.ParentDeclaration != null && ((item.ParentDeclaration.DeclarationType == DeclarationType.Module
1095+
item.ParentDeclaration != null && ((item.ParentDeclaration.DeclarationType == DeclarationType.Module
10971096
|| item.ParentDeclaration.HasPredeclaredId))
10981097
|| item.ParentScopeDeclaration.Equals(localScope)).ToList();
10991098

@@ -1152,12 +1151,22 @@ private Declaration FindProjectScopeDeclaration(string identifierName, Declarati
11521151

11531152
Debug.WriteLine("Ambiguous match in '{0}': '{1}'", localScope == null ? "(unknown)" : localScope.IdentifierName, identifierName);
11541153
}
1155-
if (temp.Count == 0)
1156-
{
1157-
Debug.WriteLine("Unknown identifier in '{0}': '{1}'", localScope == null ? "(unknown)" : localScope.IdentifierName, identifierName);
1158-
}
11591154
}
11601155

1156+
// VBA.Strings.Left function is actually called _B_var_Left;
1157+
// VBA.Strings.Left$ is _B_str_Left.
1158+
// same for all $-terminated functions.
1159+
var surrogateName = hasStringQualifier
1160+
? "_B_str_" + identifierName
1161+
: "_B_var_" + identifierName;
1162+
1163+
matches = _declarationFinder.MatchName(surrogateName).ToList();
1164+
if (matches.Count == 1)
1165+
{
1166+
return matches.Single();
1167+
}
1168+
1169+
Debug.WriteLine("Unknown identifier in '{0}': '{1}'", localScope == null ? "(unknown)" : localScope.IdentifierName, identifierName);
11611170
return null;
11621171
}
11631172

0 commit comments

Comments
 (0)