Skip to content

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

Closed
HertzDevil wants to merge 1 commit intocrystal-lang:masterfrom
HertzDevil:bug/string-byte-index-return-type
Closed

Relax return type of String#byte_index to match offset#14938
HertzDevil wants to merge 1 commit intocrystal-lang:masterfrom
HertzDevil:bug/string-byte-index-return-type

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