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

Code Inspection: Invalid use of member #2189

Closed
ThunderFrame opened this issue Aug 16, 2016 · 6 comments
Closed

Code Inspection: Invalid use of member #2189

ThunderFrame opened this issue Aug 16, 2016 · 6 comments
Labels
bug Identifies work items for known bugs feature-inspections
Milestone

Comments

@ThunderFrame
Copy link
Member

When working with interfaces and base types, VBA can compile code that will fail at run-time.

Rubberduck should try to identify such problems at inspection-time.

UserForm1 has the following property

Public Property Get FooBar() As String
  FooBar = "FooBar"
End Property
Sub FizzBuzz()

    Dim bar As UserForm1
    Set bar = UserForm1
    Debug.Print bar.FooBar

    Dim foo As UserForm
    Set foo = UserForm1
    'This compiles but fails at run-time
    Debug.Print foo.FooBar

End Sub
@retailcoder retailcoder added this to the v2.1 milestone Aug 16, 2016
@retailcoder
Copy link
Member

Might be I'm blind, but I don't see the problem with the snippet there. Did you mean to make a Property Let accessor call? Please clarify what we're looking for here.

@retailcoder
Copy link
Member

Oh duh

@retailcoder
Copy link
Member

Nevermind

@comintern
Copy link
Contributor

Now that we have the MemberNotOnInterfaceInspection (that doesn't pick this up), I'd classify this as a bug as opposed to a feature request.

@comintern comintern added the bug Identifies work items for known bugs label Mar 12, 2017
@bclothier
Copy link
Contributor

Personally, I'm a bit surprised that the sample syntax for UserForm would cause runtime errors. That is not the same behavior with the Access form.

Dim MyForm As Access.Form
Set MyForm = New Form_MyForm
MyForm.FooBar = "foo"

The FooBar member won't show on intellisense because variable is typed as a Access.Form, not Form_MyForm but it is still legal, as long the FooBar in fact exists.

We have similar situation with ADODB.Command where syntax such as MyCommand.MyStoredProcedure 123 is legal but won't be found on the ADODB.Command's interface.

So I agree with @comintern that it should be picked up by the MemberNotOnInterface inspection, to warn the users to revise their declaration or to do explicit cast to the specific type. Note that explicit cast wouldn't even apply to the ADODB.Command case, however...

@ThunderFrame
Copy link
Member Author

Also a bit like the Application.Sum function in Excel.

IIRC, COM marks the interface as extensible , and RD picks that attribute up, so we should already know that the member is potentially valid.

Vogel612 added a commit to Vogel612/Rubberduck that referenced this issue Nov 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies work items for known bugs feature-inspections
Projects
None yet
Development

No branches or pull requests

4 participants