The following 2 modules compile and run in VBE. Rubberduck parses and resolves them without error, but the status bar doesn't correctly identify some contexts, and things start going wrong when refactoring/renaming items in procedure Test.
I've only included 3 examples of incorrect/incomplete/inconsistent renamings, but I think the problems stem from Resolver issues. Place your cursor on various symbols and you can see that they're not all identified correctly.
Module bar
Option Explicit
Public Type foo
foo As String
End Type
Public Function foo(value)
foo = value
End Function
Sub test()
Dim foo As foo.foo
With foo
With .foo
Debug.Print bar.foo(.foo)
Debug.Print bar.foo(foo.foo.foo)
Debug.Print VBAProject.foo.foo(foo.foo.foo)
End With
End With
End Sub
Module foo
Option Explicit
Public Type foo
foo As bar.foo
End Type
Public Function foo(value)
foo = value
End Function
Here are various, mutually exclusive Rubberduck refactoring outcomes:
Rename local variable in procedure Bar.Test from foo to goo
Option Explicit
Public Type foo
foo As String
End Type
Public Function foo(value)
goo = value 'function return variable foo has erroneously been renamed to goo
End Function
Sub test()
'Rubberduck Rename local variable foo to goo:
Dim goo As foo.foo
With goo
With .foo
Debug.Print bar.goo(.foo) 'bar.foo has erroneously been renamed to bar.goo
Debug.Print bar.goo(goo.foo.foo) 'bar.foo has erroneously been renamed to bar.goo
Debug.Print VBAProject.foo.foo(goo.foo.foo)
End With
End With
End Sub
Rename function bar.foo to bar.goo
Option Explicit
Public Type foo
foo As String
End Type
'Rename function foo to goo
Public Function goo(value)
foo = value 'Function return value foo is not renamed
End Function
Sub test()
Dim foo As foo.foo
With foo
With .foo
Debug.Print bar.foo(.foo) 'function bar.foo is not renamed
Debug.Print bar.foo(foo.foo.foo) 'function bar.foo is not renamed
Debug.Print VBAProject.foo.foo(foo.foo.foo)
End With
End With
End Sub
Option Explicit
Public Type foo
foo As bar.foo 'function bar.foo is not renamed
End Type
Public Function foo(value)
foo = value
End Function
Rename argument type member
'Module is renamed goo
Option Explicit
Public Type foo
foo As String
End Type
Public Function foo(value)
foo = value
End Function
Sub test()
Dim foo As foo.foo
With foo
With .foo
'Rename the Type member `foo` to `goo` inside the goo.foo function call (Refactor dialog asks for rename of `bar` module)
Debug.Print goo.foo(.foo) 'module bar is renamed to goo, .foo argument is not renamed
Debug.Print goo.foo(foo.foo.foo) 'module bar is renamed to goo, .foo member is not renamed
Debug.Print VBAProject.foo.foo(foo.foo.foo) '.foo member is not renamed
End With
End With
End Sub
Option Explicit
Public Type foo
foo As bar.foo 'Module name `bar` is not renamed to `foo`
End Type
Public Function foo(value)
foo = value
End Function
Personally, I think RD's response to that code should be to run 10000 volts at 500 amps through the user's keyboard & mouse and be done with it.
I may have fixed this with #1890, where I fixed an issue where only changed modules resolved references. At least, it sure sounds like this type of issue if the resolver and everything passed.
@Hosch250 it looks more severe than just that though. Can you repro?
The second one appears to work (well, until you rename module "goo" back to "bar"). The first one doesn't, though.
Well, I suppose a tool's gotta have limitations. IMO This would be it.
The first one might have been fixed with #2398. There, I fixed an issue that the AccessibilityCheck incorrectlly assumed that local variables, i.e. variables declared in procedures, are accessible throughout the entire module and some other accessibiliy issues.
@MDoerner thanks! @ThunderFrame can you confirm whether the issue is still present?
Renamed local variable Bar.test:foo to Bar.test:zzz, got this in module Bar:
````vb
Option Explicit
Public Type foo 'note: 2 references
foo As String 'note: 0 references
End Type
Public Function foo(value)
foo = value 'note: not renamed to zzz
End Function
Sub test()
Dim zzz As foo.foo
With zzz
With .foo
Debug.Print Bar.zzz(.foo) 'note: still gets erroneously renamed
Debug.Print Bar.zzz(zzz.foo.foo) 'note: still gets erroneously renamed
Debug.Print VBAProject.foo.foo(zzz.foo.foo)
End With
End With
End Sub
````
So there is a resolver issue here, but it's such an edge case I'm deferring the issue.
Most helpful comment
Personally, I think RD's response to that code should be to run 10000 volts at 500 amps through the user's keyboard & mouse and be done with it.