rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 302 forks source link

Rubberduck Resolver Error in Access 2013 #6050

Open 11mattsj11 opened 1 year ago

11mattsj11 commented 1 year ago

First I just want to say that Rubberduck has been extremely helpful to me as I have inherited a number of Access applications. I am new to coding in general and both the Rubberduck add-in and the blog posts have been great guides as I have been working on the applications over the last 7 months. Thank you all for the work you put into this project!

One of these Access .accdb files is giving me a Resolver Error when I try to refresh Rubberduck. image I've attached the log file that Rubberduck generates. I also played around with the access file and found that there are 5 report modules that, if removed, allow Rubberduck to refresh as normal. Not sure if that is helpful to understand what causes this Resolver error or not, but I least I can still use the Add-in if I make a copy and remove these modules.

RubberduckLog.txt

Vogel612 commented 1 year ago

Seems like there is some form of addition in a place where we expect a Type. The stacktrace of the resolver error suggests the Implements definition in one of these modules contains an unexpected + or -:

System.NotSupportedException: Unexpected context type Rubberduck.Parsing.Grammar.VBAParser+AddOpContext
   at Rubberduck.Parsing.Binding.TypeBindingContext.BuildTree(Declaration module, Declaration parent, IParseTree expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext, Boolean requiresLetCoercion, Boolean isLetAssignment) in C:\projects\rubberduck\Rubberduck.Parsing\Binding\TypeBindingContext.cs:line 35
   at Rubberduck.Parsing.Binding.TypeBindingContext.Resolve(Declaration module, Declaration parent, IParseTree expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext, Boolean requiresLetCoercion, Boolean isLetAssignment) in C:\projects\rubberduck\Rubberduck.Parsing\Binding\TypeBindingContext.cs:line 20
   at Rubberduck.Parsing.Binding.BindingService.ResolveType(Declaration module, Declaration parent, ParserRuleContext expression) in C:\projects\rubberduck\Rubberduck.Parsing\Binding\BindingService.cs:line 49
   at Rubberduck.Parsing.VBA.ReferenceManagement.CompilationPasses.TypeHierarchyPass.AddImplementedInterface(Declaration potentialClassModule) in C:\projects\rubberduck\Rubberduck.Parsing\VBA\ReferenceManagement\CompilationPasses\TypeHierarchyPass.cs:line 54
      /* This is where the name of the implemented interface is read as an expression */
   at Rubberduck.Parsing.VBA.ReferenceManagement.CompilationPasses.TypeHierarchyPass.Execute(IReadOnlyCollection`1 modules) in C:\projects\rubberduck\Rubberduck.Parsing\VBA\ReferenceManagement\CompilationPasses\TypeHierarchyPass.cs:line 41
   at Rubberduck.Parsing.VBA.ReferenceManagement.ReferenceResolveRunnerBase.<>c__DisplayClass12_0.<ExecuteCompilationPasses>b__0(ICompilationPass p) in C:\projects\rubberduck\Rubberduck.Parsing\VBA\ReferenceManagement\ReferenceResolveRunnerBase.cs:line 151
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Rubberduck.Parsing.VBA.ReferenceManagement.ReferenceResolveRunnerBase.ExecuteCompilationPasses(IReadOnlyCollection`1 modules, CancellationToken token) in C:\projects\rubberduck\Rubberduck.Parsing\VBA\ReferenceManagement\ReferenceResolveRunnerBase.cs:line 151

It seems like there is an ... interesting issue around some forms of type references that happen in the Implements statements for class modules.

Could you check the affected Reports modules for such Implements statements?

11mattsj11 commented 1 year ago

Thanks for the quick response!

There are two Implements statements in the entire project I'm working on improving this, but like I said I'm still pretty new at this :) Neither of the Implements statements are in the modules of the Reports that I mentioned above. Let me know if you'd like me to share more information about where these two Implements statements are used.

If I remove all, but one of the report modules causing the issue then this is the only code in that report module.

Option Compare Database
Option Explicit

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me.EngineeringAssist <> 0 Then
        Me.txEngineeringAssist.BackColor = 12632256
    Else
        Me.txEngineeringAssist.BackColor = 16777215
    End If

End Sub

When I remove this report module then Rubberduck will refresh as normal.

Any chance it could be the names of the modules causing and issue? Each of the report modules causing the issue have non-standard names... "Report_Gantt2 - 6 Day TB Version" "Report_rptDJ&TBSchedule" etc. Wondering if the "2 - 6" or the "&" are the problem.

MDoerner commented 1 year ago

Thanks for the details. I think I have an idea what the problem is.

We use the VBE's internal type library for the project to get the supertypes of document objects. What our process does not seem to be prepared for is that the names of these supertypes do not have to conform to the usual restrictions imposed in VBA code.

I think the info provided will help a long way to reproduce the issue.

11mattsj11 commented 1 year ago

I was able to workaround the issue on my side by renaming the report modules that were causing the issue. Here are the steps I used:

  1. Create Backup of Current File
  2. Remove Modules of the reports that were causing the issue
  3. Rename the reports removing special characters
  4. Recreate the modules for each report
  5. Copy the code from the Backup file into the newly named modules
  6. Save the file
  7. Refresh Rubberduck twice, the 1st refresh still gave the resolver error but it cleared after a 2nd one for some reason.

Here is a side by side of the old version and the new version showing how I changed the module names: image

11mattsj11 commented 1 year ago

Well, I spoke too soon. Even though it did resolve initially, after closing and reopening the file it's now giving the Resolver Error again. image

retailcoder commented 1 year ago

I would guess it works if the report modules are named in standard PascalCase (without spaces), the assumption being that a module name is also a valid VBA identifier name; numbers and underscores are fine, just not as the first character.

11mattsj11 commented 1 year ago

That seems to have worked! The only thing that confuses me, is that there are quite a few other report modules that have spaces in their names and it doesn't seem to have any issue with those ones. image