-
Notifications
You must be signed in to change notification settings - Fork 300
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
Renaming enum member to conflicting class name doesn't produce warning #6237
Comments
Wow, everything around this was very thoroughly tested, ...nice find, that's the first rename bug found in years! A bug with the collision validation actually - resolution seems correct to me; the enum member is picked up as such, but the rename box does not warn about it... ...as it does when you rename, say, a blatantly conflicting one: Meanwhile it qualifies the enum member with the containing module without validating that it can legally do that (or assumes the enum is defined in a standard module), which breaks the code regardless of the naming collision: Instead Rubberduck should qualify the enum member with its parent, so in this case On a tangentially related note, the Shadowed declaration inspection should probably have a word about this too. It ships disabled by default because it's an expensive one, but in a small test project it doesn't hurt to enable it: ...but while it (correctly) identifies shadowed This is not unexpected, because the enum member and the class name can never be used in the same syntactical context, so while the names are confusing to a human reader, to VBA (and Rubberduck) the identical names are unambiguous - which is also why the rename refactoring isn't issuing a warning either. I note that I did not locally reproduce the exact same problem: whatever I do, Adding a That's the only way I could alter the semantics of the code by renaming the enum member - but then again the correct semantics are restored by fixing the qualifier to be the parent enum type name rather than the containing module name. So, I'm kind of not quite reproducing the issue here, because the enum member is always qualified with my local debug build, and that bad qualifier appears to be absent from your bug report. Still, the refactor/rename collision validation should probably warn about this (edge) case. |
Thanks for the detailed response and investigation, I may need to re-read it a few times to fully digest it all...
Yes, that's exactly it. It likely has nothing to do with the I've been following the convention of placing Enums in interface classes ever since I read this:
(https://rubberduckvba.blog/2016/07/05/oop-vba-pt-2-factories-and-cheap-hotels/)
What about the following code, or am I misunderstanding the point made?
|
With a Without the predeclared ID, the first The mis-qualifying of the renamed enum member should be a relatively easy fix; I don't think the collision validation needs to change, because if the enum member gets qualified with the correct parent declaration identifier (i.e. the name of the parent enum type), then the semantics of the code are preserved, the code remains compilable, and there is no collision introduced... so the prompt/warning would be confusing, I think. |
Aight, got a fix for this one. |
Rubberduck version information
Version 2.5.9.6321
OS: Microsoft Windows NT 10.0.19044.0, x64
Host Product: Microsoft Office x64
Host Version: 16.0.18324.20194
Host Executable: EXCEL.EXE
Description
Renaming an Enum member to the same name as a class breaks code. Rubberduck does not appear to warn about the conflict.
This probably falls somewhere between bug and feature request, but since I think notification of naming conflicts is a feature and doesn't appear in this case, I have labelled as a bug.
To Reproduce
Steps to reproduce the behavior:
Run-time error '424': Object required
IShape.cls
Rectangle.cls
Module1.bas
Expected behavior
A warning that there is a naming conflict and code may break.
Additional context
This might seem like a small issue, and it’s on the user to name things properly to avoid conflicts. But in a big project with a lot of renaming, if you mess up, there doesn’t seem to be an easy way to fix it.
The text was updated successfully, but these errors were encountered: