@@ -30,7 +30,7 @@ public class DeclarationFinder
30
30
31
31
private readonly IReadOnlyDictionary < QualifiedModuleName , IFailedResolutionStore > _failedResolutionStores ;
32
32
private readonly ConcurrentDictionary < QualifiedModuleName , IMutableFailedResolutionStore > _newFailedResolutionStores ;
33
- private readonly ConcurrentDictionary < QualifiedMemberName , ConcurrentBag < Declaration > > _newUndeclared ;
33
+ private readonly ConcurrentDictionary < ( QualifiedMemberName memberName , DeclarationType declarationType ) , ConcurrentBag < Declaration > > _newUndeclared ;
34
34
35
35
private IDictionary < ( QualifiedModuleName module , int annotatedLine ) , List < IParseTreeAnnotation > > _annotations ;
36
36
private IDictionary < Declaration , List < ParameterDeclaration > > _parametersByParent ;
@@ -78,7 +78,7 @@ public DeclarationFinder(
78
78
_failedResolutionStores = failedResolutionStores ;
79
79
80
80
_newFailedResolutionStores = new ConcurrentDictionary < QualifiedModuleName , IMutableFailedResolutionStore > ( ) ;
81
- _newUndeclared = new ConcurrentDictionary < QualifiedMemberName , ConcurrentBag < Declaration > > ( ) ;
81
+ _newUndeclared = new ConcurrentDictionary < ( QualifiedMemberName memberName , DeclarationType declarationType ) , ConcurrentBag < Declaration > > ( ) ;
82
82
83
83
var collectionConstructionActions = CollectionConstructionActions ( declarations , annotations ) ;
84
84
ExecuteCollectionConstructionActions ( collectionConstructionActions ) ;
@@ -986,13 +986,14 @@ public Declaration OnUndeclaredVariable(Declaration enclosingProcedure, string i
986
986
null ,
987
987
! isReDimVariable ) ;
988
988
989
- var hasUndeclared = _newUndeclared . ContainsKey ( enclosingProcedure . QualifiedName ) ;
989
+ var enclosingScope = ( enclosingProcedure . QualifiedName , enclosingProcedure . DeclarationType ) ;
990
+ var hasUndeclared = _newUndeclared . ContainsKey ( enclosingScope ) ;
990
991
if ( hasUndeclared )
991
992
{
992
993
ConcurrentBag < Declaration > undeclared ;
993
- while ( ! _newUndeclared . TryGetValue ( enclosingProcedure . QualifiedName , out undeclared ) )
994
+ while ( ! _newUndeclared . TryGetValue ( enclosingScope , out undeclared ) )
994
995
{
995
- _newUndeclared . TryGetValue ( enclosingProcedure . QualifiedName , out undeclared ) ;
996
+ _newUndeclared . TryGetValue ( enclosingScope , out undeclared ) ;
996
997
}
997
998
var inScopeUndeclared = undeclared . FirstOrDefault ( d => d . IdentifierName == identifierName ) ;
998
999
if ( inScopeUndeclared != null )
@@ -1003,7 +1004,7 @@ public Declaration OnUndeclaredVariable(Declaration enclosingProcedure, string i
1003
1004
}
1004
1005
else
1005
1006
{
1006
- _newUndeclared . TryAdd ( enclosingProcedure . QualifiedName , new ConcurrentBag < Declaration > { undeclaredLocal } ) ;
1007
+ _newUndeclared . TryAdd ( enclosingScope , new ConcurrentBag < Declaration > { undeclaredLocal } ) ;
1007
1008
}
1008
1009
return undeclaredLocal ;
1009
1010
}
@@ -1067,14 +1068,16 @@ public Declaration OnBracketedExpression(string expression, ParserRuleContext co
1067
1068
Debug . Assert ( hostApp != null , "Host application project can't be null. Make sure VBA standard library is included if host is unknown." ) ;
1068
1069
1069
1070
var qualifiedName = hostApp . QualifiedName . QualifiedModuleName . QualifyMemberName ( expression ) ;
1071
+ var declarationType = DeclarationType . BracketedExpression ;
1072
+ var undeclaredScope = ( qualifiedName , declarationType ) ;
1070
1073
1071
- if ( _newUndeclared . TryGetValue ( qualifiedName , out var undeclared ) )
1074
+ if ( _newUndeclared . TryGetValue ( undeclaredScope , out var undeclared ) )
1072
1075
{
1073
1076
return undeclared . SingleOrDefault ( ) ;
1074
1077
}
1075
1078
1076
1079
var item = new Declaration ( qualifiedName , hostApp , hostApp , Tokens . Variant , string . Empty , false , false , Accessibility . Global , DeclarationType . BracketedExpression , context , null , context . GetSelection ( ) , true , null ) ;
1077
- _newUndeclared . TryAdd ( qualifiedName , new ConcurrentBag < Declaration > { item } ) ;
1080
+ _newUndeclared . TryAdd ( undeclaredScope , new ConcurrentBag < Declaration > { item } ) ;
1078
1081
return item ;
1079
1082
}
1080
1083
0 commit comments