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

Fix Atomic#max and #min for signed enums #13524

Merged

Conversation

HertzDevil
Copy link
Contributor

Since enum types are not subtypes of their base types, the check T < Int::Signed in Atomic(T)#max and #min will always return false for enum types, which makes signed enums always use the unsigned interpretation. This PR adds the necessary runtime type checks. (The TypeNode#base_type suggested in #9803 could turn this runtime check into a compile-time one.)

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:multithreading labels May 29, 2023
Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitively a good example for base_type macro method. In any case, better be correct first, and at a later stage we can rewrite it to avoid the runtime cost.

@straight-shoota straight-shoota added this to the 1.9.0 milestone Jun 5, 2023
@straight-shoota straight-shoota merged commit 9055de0 into crystal-lang:master Jun 7, 2023
@HertzDevil HertzDevil deleted the bug/signed-atomic-enum-max-min branch June 15, 2023 12:21
Blacksmoke16 pushed a commit to Blacksmoke16/crystal that referenced this pull request Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:multithreading topic:stdlib:concurrency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants