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

Recent Resolver Error on VBE-compilable code #6187

Open pflugs30 opened 11 months ago

pflugs30 commented 11 months ago

Rubberduck version information The info below can be copy-paste-completed from the first lines of Rubberduck's log or the About box:

Version 2.5.9.6314 OS: Microsoft Windows NT 10.0.22631.0, x64 Host Product: Microsoft Office x64 Host Version: 16.0.16130.20846 Host Executable: EXCEL.EXE

Description After updating to the recent public release of Rubberduck, I started seeing a Resolver Error on compilable code which used to be just fine. Using the log files, I isolated the issue to a single method.

To Reproduce Steps to reproduce the behavior:

  1. Open Excel and create a new blank workbook.
  2. Open the VBE and add a single code module.
  3. Paste the following code: Module1.zip
  4. Compile the code to show the VBE can parse it.
  5. Click the Rubberduck menu --> Refresh
  6. Observe Rubberduck will show a Resolver Error.

Expected behavior Rubberduck should be able to parse and resolve this code just fine.

Screenshots N/A

Logfile RubberduckLog.txt

Additional context Specifically, I've discovered these lines to be the problem:

        If utc_HasOffset Then
            ParseIso = ParseIso - utc_Offset
        End If

When these lines are commented, then RD can parse and resolve all day. All these variables are defined and found in the function.

MDoerner commented 11 months ago

Thanks for the report. I think I have an idea why there is an exception in the resolution. However, if that code is the culprit, I think something imight be already wrong when parsing the code. The resolver seems to fail on a single line if statement with empty then statement.

I will have a look later and see what I can do.

pflugs30 commented 11 months ago

Please let me know if you'd like me to send a broader log file. I think what I sent covers the parsing, but I could be mistaken.

jimmyli97 commented 9 months ago

If anyone else has this issue then the workaround for now is to remove the empty line e.g. If utc_NegativeOffset Then utc_Offset = -utc_Offset instead of If utc_NegativeOffset Then: utc_Offset = -utc_Offset

Irubataru commented 9 months ago

I am also having this issue, but my code base is massive and I can't really fix it with workarounds. I am trying to find a usable version of Rubberduck. Due to #6152 I also can't use v2.5.9.6291. I tried v2.5.2.6260-pre, but I am having some performance issues with that release.

tommy9 commented 9 months ago

I've submitted a pull request with a fix. For reference here, a simplified error case is shown below with explanation of how the parse went wrong in the comments:

Sub test()
    If True Then: A = 1 'matches an ifStmt incorrectly but only when have an ifStmt later

    If False Then       'when above goes wrong, this is matched as singleLineIfStmt with empty THEN clause which is wrong. If that didn't happen, the above would not match ifStmt and then try to match singleLineIfStmt as it should
        A = 5
    End If
End Sub