-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow redefining None to 0 for @[Flags] enum #6160
Allow redefining None to 0 for @[Flags] enum #6160
Conversation
In general I'm +1 to this, not sure I like |
Mentioning I would be very happy to have just |
Yeah I know @oprypin I just wanted to add some context, and I needed to mention |
I just added a better empty enum check that ignores None & All in flags enums, now that they are allowed |
@@ -569,7 +569,13 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor | |||
is_flags: enum_type.flags?) | |||
end | |||
|
|||
if enum_type.types.empty? | |||
nb_members = enum_type.types.size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's nb_members
supposed to mean? I'd suggest to use a more descriptive name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the number of members, maybe number_of_members
then? it just felt too long ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no "too long" for names, only "too short" 😄 num_members
would be fine, tough. Or members_size
, enum_size
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num_members
is good 😃 ty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think there is a spec missing regarding how All is ignored. From the PR initial message it wasn't clear if the user needs to A | B | C
or not
There is no change in behavior of |
Yeah sorry if it wasn't clear @bcardiff, the title only mention the possibility to redefine None, not All. The PR inital msg is providing context and explanations, maybe it should have gone in an issue. |
Thank you! |
No, thank you, @bew =) |
Followup on #4395 (comment)
#4395 now prevents
All
&None
in@[Flags]
enums.But as @oprypin pointed out / demonstrated, redefining
None
&All
can be useful for documentation purpose.To this end:
None
should always be0
, and All should always be all the values OR-ed together.So something like this should work:
It's easy to handle
None
, just need to check it's0
.About
All
, first it's very tedious to repeat all members, second it's harder to detect if there are more members after it. To simplifyAll
and still be able to documente it, there could be a special value likeAll = :all
that will skip this member but retain its doc somehow...As handling
None
is easy I implemented it in this PR.Also, I don't think
All
is common when using enum flags, so I think it's ok to not be able to document it.WDYT?