Skip to content

Breaking Change: make String::op_get return Int #1861

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Yu-zh
Copy link
Collaborator

@Yu-zh Yu-zh commented Apr 1, 2025

No description provided.

Copy link

peter-jerry-ye-code-review bot commented Apr 1, 2025

Documentation needs to be updated to reflect the return type change

Category
Maintainability
Code Snippet
pub fn String::op_get(self : String, idx : Int) -> Int = "%string_get"
Recommendation
Add documentation explaining that the function now returns the Unicode code point (Int) instead of a Char
Reasoning
The change from Char to Int is significant for API users and should be clearly documented to avoid confusion. Users need to know they're getting a numeric code point instead of a character.

Consider adding helper method for character code point conversion

Category
Maintainability
Code Snippet
test "String::op_get" {
let s = "Hello, 世界!"
inspect!(s[0], content="72")
inspect!(s[7], content="19990")
}
Recommendation
Add a utility function to convert between Int code points and Char, like from_code_point(i: Int) -> Char
Reasoning
Since the indexing operation now returns code points instead of characters, users might frequently need to convert between the two. A helper method would improve usability.

Panic message for out-of-bounds might need update

Category
Correctness
Code Snippet
test "panic String::op_get/out_of_bounds" {
let s = "Hello"
s[-1]
}
Recommendation
Ensure the panic message mentions that the operation returns a code point, if it currently mentions returning a character
Reasoning
Error messages should be consistent with the actual behavior of the function to avoid misleading users when errors occur.

@coveralls
Copy link
Collaborator

coveralls commented Apr 1, 2025

Pull Request Test Coverage Report for Build 6285

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 91.834%

Totals Coverage Status
Change from base Build 6283: 0.0%
Covered Lines: 5679
Relevant Lines: 6184

💛 - Coveralls

@Yu-zh Yu-zh force-pushed the change-type-of-string-op-get branch from 59d61c2 to 67deb0e Compare April 1, 2025 14:02
@Yu-zh Yu-zh marked this pull request as draft April 1, 2025 14:07
@Yu-zh Yu-zh force-pushed the change-type-of-string-op-get branch from 67deb0e to cb61835 Compare April 2, 2025 07:22
@Yu-zh Yu-zh marked this pull request as ready for review April 7, 2025 03:41
@Yu-zh Yu-zh marked this pull request as draft April 7, 2025 06:26
@Yu-zh Yu-zh force-pushed the change-type-of-string-op-get branch from 168961c to ad416ee Compare April 11, 2025 08:11
@Yu-zh Yu-zh marked this pull request as ready for review April 14, 2025 02:01
@bobzhang bobzhang force-pushed the change-type-of-string-op-get branch from e4cb96d to b1f5574 Compare April 15, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants