Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Instantiated inspection ignores module-level variables #3568

Open
ThunderFrame opened this issue Nov 25, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@ThunderFrame
Copy link
Member

commented Nov 25, 2017

The following code generates Object variable reference is auto-instantiated inspections for fizz and buzz but not for foo and bar

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
@retailcoder

This comment has been minimized.

Copy link
Member

commented Nov 25, 2017

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 As New pretty much implied that it means to live as long as the class it's declared in.

I guess it wouldn't hurt to enhance the inspection to also look at module scope... The meta/descriptions need to be updated too.

@ThunderFrame

This comment has been minimized.

Copy link
Member Author

commented Nov 25, 2017

Maybe split it into 2 inspections? The descriptions could vary by module/procedure scope, with differing levels of severity and caution/advice to the user? Likewise, the inspections could then be disabled per scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.