Skip to content

Fix Range#size return type to Int32#14588

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
straight-shoota:fix/range-size-return-type
Sep 5, 2024
Merged

Fix Range#size return type to Int32#14588
straight-shoota merged 2 commits intocrystal-lang:masterfrom
straight-shoota:fix/range-size-return-type

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
@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