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 Range#size return type to Int32 #14588

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented May 13, 2024

Resolves #14587

The super implementation Enumerable#size has the same type restriction already.

See also #13648 (comment)

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:collection labels May 13, 2024
@straight-shoota straight-shoota self-assigned this May 13, 2024
@straight-shoota
Copy link
Member Author

straight-shoota commented May 13, 2024

Hm, actually this can overflow on ranges of Int types that are bigger than Int32 🤔
Should we only cast to Int32 on smaller types?

@beta-ziliani
Copy link
Member

I'm afraid there's no good solution here. The good part of raising on overflow is that if it fits, it works. The bad part is that the failure is at runtime...

An alternative, as good or bad, is to statically fail on > Int32 types and have people do the math themselves 🤷

@straight-shoota straight-shoota changed the title Fix Rang#size return type to Int32 Fix Range#size return type to Int32 May 24, 2024
@straight-shoota straight-shoota added this to the 1.14.0 milestone Sep 4, 2024
@straight-shoota straight-shoota merged commit db2ecd7 into crystal-lang:master Sep 5, 2024
61 checks passed
@straight-shoota straight-shoota deleted the fix/range-size-return-type branch September 5, 2024 22:36
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:stdlib:collection
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Range#size returns an Union instead of an Int32
2 participants