Join GitHub today
Auto Instantiated inspection ignores module-level variables #3568
The following code generates Object variable reference is auto-instantiated inspections for
Option Explicit Private foo(10) As New Class2 Private bar As New Class2 Sub test() Dim fizz(10) As New Class2 Dim buzz As New Class2 Debug.Print foo(1) Is Nothing, bar Is Nothing, fizz(1) Is Nothing, buzz Is Nothing Set foo(1) = Nothing Set bar = Nothing Set fizz(1) = Nothing Set buzz = Nothing Debug.Print foo(1) Is Nothing, bar Is Nothing, fizz(1) Is Nothing, buzz Is Nothing End Sub
That's by design actually; the inspection explicitly only looks at procedure-scope variables. Arguably the issue is the same at module-scope, but it was thought that a module-level variable declared
I guess it wouldn't hurt to enhance the inspection to also look at module scope... The meta/descriptions need to be updated too.