@@ -266,10 +266,10 @@ private Declaration ResolveInternal(ParserRuleContext callSiteContext, Declarati
266
266
}
267
267
else
268
268
{
269
- callee = FindLocalScopeDeclaration ( identifierName , localScope )
270
- ?? FindModuleScopeProcedure ( identifierName , localScope , accessorType , isAssignmentTarget )
271
- ?? FindModuleScopeDeclaration ( identifierName , localScope )
272
- ?? FindProjectScopeDeclaration ( identifierName ) ;
269
+ callee = FindLocalScopeDeclaration ( identifierName , localScope )
270
+ ?? FindModuleScopeProcedure ( identifierName , localScope , accessorType , isAssignmentTarget )
271
+ ?? FindModuleScopeDeclaration ( identifierName , localScope )
272
+ ?? FindProjectScopeDeclaration ( identifierName ) ;
273
273
}
274
274
275
275
if ( callee == null )
@@ -373,6 +373,8 @@ private Declaration ResolveInternal(VBAParser.ICS_S_MembersCallContext context,
373
373
}
374
374
parent = ResolveInternal ( context . iCS_S_ProcedureOrArrayCall ( ) , localScope , accessorType , hasExplicitLetStatement , isAssignmentTarget )
375
375
?? ResolveInternal ( context . iCS_S_VariableOrProcedureCall ( ) , localScope , accessorType , hasExplicitLetStatement , isAssignmentTarget ) ;
376
+
377
+ parent = ResolveType ( parent ) ;
376
378
}
377
379
378
380
if ( parent != null )
@@ -453,24 +455,6 @@ private Declaration ResolveInternal(VBAParser.ICS_B_ProcedureCallContext context
453
455
return callee ;
454
456
}
455
457
456
- private void ResolveIdentifier ( VBAParser . AmbiguousIdentifierContext context )
457
- {
458
- if ( context == null )
459
- {
460
- return ;
461
- }
462
-
463
- var identifier = ResolveInternal ( context , _currentScope ) ;
464
- if ( identifier == null )
465
- {
466
- return ;
467
- }
468
-
469
- var reference = CreateReference ( context , identifier ) ;
470
- identifier . AddReference ( reference ) ;
471
- _alreadyResolved . Add ( reference . Context ) ;
472
- }
473
-
474
458
public void Resolve ( VBAParser . ICS_B_ProcedureCallContext context )
475
459
{
476
460
if ( _alreadyResolved . Contains ( context ) )
@@ -544,6 +528,7 @@ public void Resolve(VBAParser.ICS_S_MembersCallContext context)
544
528
{
545
529
parent = ResolveInternal ( context . iCS_S_ProcedureOrArrayCall ( ) , _currentScope )
546
530
?? ResolveInternal ( context . iCS_S_VariableOrProcedureCall ( ) , _currentScope ) ;
531
+ parent = ResolveType ( parent ) ;
547
532
}
548
533
549
534
if ( parent != null && parent . Context != null )
@@ -674,32 +659,32 @@ public void Resolve(VBAParser.ForEachStmtContext context)
674
659
675
660
public void Resolve ( VBAParser . ImplementsStmtContext context )
676
661
{
677
- ResolveIdentifier ( context . ambiguousIdentifier ( ) ) ;
662
+ ResolveInternal ( context . ambiguousIdentifier ( ) , _currentScope ) ;
678
663
}
679
664
680
665
public void Resolve ( VBAParser . RaiseEventStmtContext context )
681
666
{
682
- ResolveIdentifier ( context . ambiguousIdentifier ( ) ) ;
667
+ ResolveInternal ( context . ambiguousIdentifier ( ) , _currentScope ) ;
683
668
}
684
669
685
670
public void Resolve ( VBAParser . ResumeStmtContext context )
686
671
{
687
- ResolveIdentifier ( context . ambiguousIdentifier ( ) ) ;
672
+ ResolveInternal ( context . ambiguousIdentifier ( ) , _currentScope ) ;
688
673
}
689
674
690
675
public void Resolve ( VBAParser . FileNumberContext context )
691
676
{
692
- ResolveIdentifier ( context . ambiguousIdentifier ( ) ) ;
677
+ ResolveInternal ( context . ambiguousIdentifier ( ) , _currentScope ) ;
693
678
}
694
679
695
680
public void Resolve ( VBAParser . ArgDefaultValueContext context )
696
681
{
697
- ResolveIdentifier ( context . ambiguousIdentifier ( ) ) ;
682
+ ResolveInternal ( context . ambiguousIdentifier ( ) , _currentScope ) ;
698
683
}
699
684
700
685
public void Resolve ( VBAParser . FieldLengthContext context )
701
686
{
702
- ResolveIdentifier ( context . ambiguousIdentifier ( ) ) ;
687
+ ResolveInternal ( context . ambiguousIdentifier ( ) , _currentScope ) ;
703
688
}
704
689
705
690
public void Resolve ( VBAParser . VsAssignContext context )
@@ -782,14 +767,22 @@ private Declaration FindModuleScopeDeclaration(string identifierName, Declaratio
782
767
return matches . SingleOrDefault ( item =>
783
768
item . ParentScope == localScope . ParentScope
784
769
&& ! item . DeclarationType . HasFlag ( DeclarationType . Member )
785
- && ! _moduleTypes . Contains ( item . DeclarationType ) ) ;
770
+ && ! _moduleTypes . Contains ( item . DeclarationType )
771
+ && ( item . DeclarationType != DeclarationType . Event || IsLocalEvent ( item , localScope ) ) ) ;
786
772
}
787
773
catch ( InvalidOperationException )
788
774
{
789
775
return null ;
790
776
}
791
777
}
792
778
779
+ private bool IsLocalEvent ( Declaration item , Declaration localScope )
780
+ {
781
+ return item . DeclarationType == DeclarationType . Event
782
+ && localScope . Project == _currentScope . Project
783
+ && localScope . ComponentName == _currentScope . ComponentName ;
784
+ }
785
+
793
786
private Declaration FindModuleScopeProcedure ( string identifierName , Declaration localScope , ContextAccessorType accessorType , bool isAssignmentTarget = false )
794
787
{
795
788
if ( localScope == null )
@@ -818,6 +811,7 @@ private Declaration FindProjectScopeDeclaration(string identifierName)
818
811
{
819
812
return matches . SingleOrDefault ( item =>
820
813
! item . DeclarationType . HasFlag ( DeclarationType . Member )
814
+ && item . DeclarationType != DeclarationType . Event // events can't be called outside the class they're declared in
821
815
&& ( item . Accessibility == Accessibility . Public
822
816
|| item . Accessibility == Accessibility . Global
823
817
|| _moduleTypes . Contains ( item . DeclarationType ) /* because static classes are accessed just like modules */ ) ) ;
0 commit comments