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

Comments

Projects
None yet
4 participants
@ThunderFrame
Copy link
Member

commented Aug 16, 2016

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

This comment has been minimized.

Copy link
Member

commented Sep 7, 2016

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

This comment has been minimized.

Copy link
Member

commented Sep 7, 2016

Oh duh

@retailcoder

This comment has been minimized.

Copy link
Member

commented Sep 7, 2016

Nevermind

@comintern

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2017

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 label Mar 12, 2017

@bclothier

This comment has been minimized.

Copy link
Contributor

commented Nov 25, 2017

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

This comment has been minimized.

Copy link
Member Author

commented Nov 25, 2017

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

@Hosch250 Hosch250 closed this in ef11a05 Nov 26, 2017

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.