Fix Enum#includes?
to require all bits set
#13229
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The implementation of
Enum#includes?
is too lax and returns true if any common bit is set (#13160 (comment)). This patch checks that all bits are set.@HertzDevil Suggested this might need to be merged together with #13160, but I would see it as fix that makes sense on its own. We can pool them together, but I don't think it's strictly necessary...?
The behaviour of
None
may need some explanation. The current implementation always returnsfalse
when the parameter isNone
(even forNone.includes?(None)
). Some code may depend on this quirk, including the implementation ofEnum.each
(hence this needed to be fixed as well).I wouldn't expect much code to be affected and it's probably best to apply this change regardless. It is a bug and fixing it may have a small chance of breaking someone's code.