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

Relax return type of String#byte_index to match offset #14938

Conversation

HertzDevil
Copy link
Contributor

Like #10972, but for String#byte_index.

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:text labels Aug 23, 2024
@straight-shoota
Copy link
Member

straight-shoota commented Aug 23, 2024

I know we did this before, but it's not the ideal solution. I think ideally we should restrict the return type and offset both to Int32. If offset can take a different type, the return type would be a union type. And there's really no good reason for that. An index is always Int32 in Crystal's stdlib.

It was okay to revert back in #10972 to fix a regression. Now these restrictions on #byte_index have been in place since Crystal 0.35 (introduced #8447), so it's not really a quick regression fix anymore.

I think the more reasonable action would be to add Int32 restriction on the offset parameter. This would document the implict restriction that has been observed for the past four years.

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:text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants