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

'@Ignore ImplicitByRefModifier doesn't work with a line continuation #4926

Open daFreeMan opened 5 years ago

daFreeMan commented 5 years ago

Rubberduck version information Version 2.4.1.4666 OS: Microsoft Windows NT 10.0.15063.0, x64 Host Product: Microsoft Office 2016 x64 Host Version: 16.0.4822.1000 Host Executable: EXCEL.EXE

Description Adding '@Ignore ImplicitByRefModifier to a function declaration does not work if there is a line continuation (_) in the declaration.

To Reproduce Steps to reproduce the behavior:

  1. Write a function declaration with an implicit ByRef
  2. Edit in a line continuation
  3. Use the Code Inspection QuickFix Ignore Once
  4. Parse
  5. See error

Expected behavior It works just fine without the line continuation, it should work equally well with the line continuation

Logfile RubberduckLog.txt

Additional context This code:

'@Ignore ImplicitByRefModifier
    Private Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal IpBuffer As String, nSize As Long) As Long
'@Ignore ImplicitByRefModifier
    Private Declare PtrSafe Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
                             (ByVal lpBuffer As String, nSize As Long) As Long

Generates one Parameter 'nSize' is implicitly passed by reference inspection on the second declaration (GetComputerName).

This, however, does not generate an inspection result for either variation:

'@Ignore ImplicitByRefModifier
Private Function foo(bar As Long) As Long
  foo = 1
End Function

'@Ignore ImplicitByRefModifier
Private Function bar(foo As Long) _
    As Long
  bar = 2
End Function
Vogel612 commented 5 years ago

Yea, I assume that's because a part of the logic for ignore annotations may fall back to checking the annotation based on the module's lines as retrieved from the VBE, which only respects physical lines, not logical lines...

MDoerner commented 5 years ago

Quite exactly. If there is any physical line with code in between, an annotation does not apply. This is how annotations currently work.

daFreeMan commented 5 years ago

@MDoerner I'm not quite sure I buy that logic - in the simple code I provided at the end, the 2nd @Ignore does work. i.e. there is no inspection generated on Function bar.

I see the difference in the declarations. If I put the _ before (foo As Long), I do get the false positive inspection.