8000 Move deprecated blocks in string package by bobzhang · Pull Request #2318 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Move deprecated blocks in string package #2318

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

Merged

Conversation

bobzhang
Copy link
Contributor

Summary

  • consolidate deprecated string functions in deprecated.mbt
  • remove deprecated blocks from string.mbt and view.mbt
  • remove stray docstrings left behind in string.mbt

Testing

  • moon fmt
  • moon info
  • moon test
  • moon check

https://chatgpt.com/codex/tasks/task_e_685963c08e6c83208721f1364ce6039a

Copy link
peter-jerry-ye-code-review bot commented Jun 23, 2025
Consider adding migration guide in deprecation notices

Category
Maintainability
Code Snippet
#deprecated("Use s.find(substr) instead. If the optional argument from is not 0, take view from the string first. Please do not use an invalid from argument.")
Recommendation
Include code example in deprecation message, e.g.: #deprecated("Use s.find(substr) instead. Example: Replace index_of(s, 'x', 5) with s.view(start_offset=5).find('x').")
Reasoning
Complex migration paths are harder to understand without concrete examples. Adding example transformations makes it clearer how to update existing code.

Size hint calculation in concat() may overflow

Category
Performance
Code Snippet
size_hint = size_hint << 1
Recommendation
Add overflow check or use a more conservative growth strategy: size_hint = if size_hint > MAX_INT/2 { MAX_INT } else { size_hint << 1 }
Reasoning
Left shifting integers can cause overflow with large arrays. Even though this is deprecated code, it should still handle edge cases safely.

Inconsistent handling of empty strings in index functions

Category
Correctness
Code Snippet
if str.length() == 0 { self.length() } else { -1 }
Recommendation
Consider consistent behavior - either always return -1 for out of bounds or always handle empty string as a special case
Reasoning
The current code returns different values for empty strings based on the from parameter, which could be confusing. Consistency would make the behavior more predictable.

@coveralls
Copy link
Collaborator
coveralls commented Jun 23, 2025

Pull Request Test Coverage Report for Build 7452

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 90.117%

Totals Coverage Status
Change from base Build 7447: 0.0%
Covered Lines: 8544
Relevant Lines: 9481

💛 - Coveralls

@bobzhang bobzhang merged commit 63ef8bb into main Jun 23, 2025
16 checks passed
@bobzhang bobzhang deleted the r0ymiu-codex/group-deprecated-functions-into-deprecated.mbt branch June 23, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0