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

Possible VBA bug: Instatiation of a class using default memeber calls default member of wrong class. #6147

Open
FullValueRider opened this issue Aug 29, 2023 · 6 comments
Labels
support Whether you're using Rubberduck or you've forked it and have questions, never hesitate to ask!

Comments

@FullValueRider
Copy link

I'm seeking confirmation that I'm seeing an issue and not just suffering from familiarity blindness. I've attached the relevant xlam / twinbasic project below.

I have a number of classes of similar name which have a factory method declared as the default member.

I have encountered a situation where a call to instantiate SeqA object actually instantiates a SeqC object.

The specific line in question is (where Me is the SeqC object)

Set PopRange = SeqA(Me.Reverse)

It is possibly more efficient to use

Set PopRange = SeqA(Me).Reverse

In the first case, test23c in module TestSeqC passes
In the latter case Test23C in module TestSeqC fails

When stepping through the code this the failure in the latter case appears to be due to the call to SeqA default method is actually instantiating a SeqC rather than a SeqA. I can't see any issue with my code so I think VBA is getting something wrong or there is a subtlety I don't understand.

If I export the code to twinBasic then Test23C passes in both of the above cases so, clutching at straws, I'm assuming the issue lies with VBA.

Would someone be kind enough to check my finding?
VBALibxlam.zip

VBALib_SeqCforSeqA.zip

@FullValueRider FullValueRider added the support Whether you're using Rubberduck or you've forked it and have questions, never hesitate to ask! label Aug 29, 2023
@MarkJohnstoneGitHub
Copy link

MarkJohnstoneGitHub commented Sep 9, 2023

@FullValueRider How did you go? I had a quick peek a couple of days ago. Appears what you're doing is putting a default property on a factory method, unusual. Apart from that that was getting confused with the naming. SeqA, SeqC etc.
Preferable would liked some github links directly to the VBA code to examine incase getting confused exactly what to check and can examine online without booting up Excel.

Hmm "instantiating a SeqC rather than a SeqA."
Is the twinBasic test exactly the same as the Rubberduck test?
Maybe try some independent examples and step through. Highly unlikely an issue with the default property in VBA.
Check the VBA attributes for class member default property in question incase out of sync or not generated?
Or if another property for that class already the default member?

When get some time over the weekend will have another look.

Good luck. 😁

@FullValueRider
Copy link
Author

Thanks for taking the time to look at this issue. The github repository is

https://github.com/FullValueRider/VBALib

SeqA, SeqC, SeqH etc are arraylist/collection replacements, the last letter denoting the 'technology' used to store items. The term seq I pinched from the nim programming language.

The work around for the issue to to specifically call the constructor method

Dim myS as SeqA
Set myS = SeqA.Deb(1,2,3,4,5,6,7,8,9)

' rather than
Dim myS as SeqA
Set myS = SeqA(1,2,3,4,5,6,7,8,9)

@retailcoder
Copy link
Member

I also downloaded the files a few days ago and looked at the code, but I'm not seeing how it would be possible that the wrong type would be instantiated, or how implicit vs explicit invocation might differ. Would be interesting to be able to list objects and their respective members' addressing.

@FullValueRider
Copy link
Author

Sorry for my lack of clarity.

If you would kindly run SeqAtests in Module TestSeqA. What do you see in the immediate window.?

@Greedquest
Copy link
Contributor

Something to do with the parameterless SeqC constructor being invoked, resulting in an empty container being passed which may be handled differently in the SeqA constructor

Complete guess

Is SeqC constructor being called?

@Greedquest
Copy link
Contributor

Hmmm nah you would need brackets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Whether you're using Rubberduck or you've forked it and have questions, never hesitate to ask!
Projects
None yet
Development

No branches or pull requests

4 participants