-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Pure enums allow using the same name but allow nonqualification with quirky behaviour #8066
Comments
I am not sure if this is about type
MyEnum {.pure.} = enum
valueA, valueB, valueC, valueD
echo valueA The manual states that this code should give an error because of the KR Axel |
I agree this should be considered a bug, it defeats the whole purpose of using |
There was a discussion not so long ago where @Araq argued that there is no issue in allowing non-qualified access to pure enums, as long as no ambiguity arises. Hence the condition on pure enums was relaxed a bit. The problem here is that there is an ambiguity. In my opinion, allowing only qualified access to pure enums is a simple and clear rule to explain and to follow, and I do not see much value in allowing non qualified access. |
Yes, you don't see much value. I've actually tried to use the old |
And then these rules fail to be applied in DSLs... |
@Araq I actually don't have any problems in relaxing the conditions for pure enums, the current issue is just a bug that needs to be ironed out. I was just trying to reconstruct why things changed. Even if I don't see much value in this particular circumstance, I am mostly agnostic about whatver choice gest implemented for pure enums |
I'd also be alright with it after hearing the rationale, provided this bug gets fixed and the compiler gives useful error messages similar to other ambiguities. |
Relevant discussion in 2017 from @dom96, @PMunch, @Araq and me https://irclogs.nim-lang.org/22-10-2017.html#13:54:23
I still think if the pragma is here to stay, But, I think this is unnecessary policing by the compiler, assuming this is an internal enum, you're free to use your preferred style (always qualifying, or qualifying when necessary), if it's a public module, don't force your style on other projects. All in all I think this should be handled in a Nim linter, with options chosen by the library authors, not in the compiler. |
Just an opinion, |
I think the focus was mishandled in this issue, it's also a matter of not having to deal with hungarian notation or the full name of the enum in the enum member like type StreetLight {.pure.} = enum
red, yellow, green
let foo = StreetLight.red instead of type StreetLight = enum
stlRed, stlYellow, stlGreen
let foo = stlRed |
The text was updated successfully, but these errors were encountered: