feat(string): add parse_bigint (Fixes #3566)#3679
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds parse_bigint as an error-raising string-to-BigInt parser, re-exports it through the string strconv surface, and updates BigInt::from_string to be a panic-on-error wrapper.
Changes:
- Introduce
@bigint.parse_bigint(StringView, base?: Int) -> BigInt raisewith consistent error strings ("invalid syntax","invalid base"). - Re-export
parse_bigintfrom@stringand wire package imports / generated API stubs. - Add unit tests for
parse_bigintin bothbigintandstring.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| string/strconv.mbt | Re-exports parse_bigint via the string strconv API surface. |
| string/pkg.generated.mbti | Adds generated signature for @string.parse_bigint and imports bigint. |
| string/parse_bigint_test.mbt | Adds tests covering @string.parse_bigint basic parsing and error behavior. |
| string/moon.pkg | Adds bigint dependency to support the new re-export. |
| bigint/strconv_errors.mbt | Centralizes parse error messages and helper raisers. |
| bigint/pkg.generated.mbti | Exposes generated signature for @bigint.parse_bigint. |
| bigint/parse_bigint_test.mbt | Adds test coverage for valid/invalid inputs and base validation. |
| bigint/moon.pkg | Adds imports needed for new error raising and tests. |
| bigint/bigint_nonjs.mbt | Implements parse_bigint and refactors existing parsing to raise errors instead of aborting. |
| bigint/bigint_js.mbt | Implements parse_bigint for JS backend and refactors radix parsing to raise errors. |
| bigint/bigint.mbt | Updates JSON decoding to map parse failures into JsonDecodeError. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pub fn BigInt::from_string(input : String, radix? : Int = 10) -> BigInt { | ||
| parse_bigint(input.view(), base=radix) catch { | ||
| Failure(msg) => abort(msg) | ||
| _ => abort("invalid syntax") | ||
| } |
| pub fn BigInt::from_string(str : String, radix? : Int = 10) -> BigInt { | ||
| parse_bigint(str.view(), base=radix) catch { | ||
| Failure(msg) => abort(msg) | ||
| _ => abort("invalid syntax") | ||
| } |
|
All checks passed, please review and merge this PR when you have time, thanks. @bobzhang |
dcd979f to
8f78032
Compare
Yu-zh
left a comment
There was a problem hiding this comment.
Thanks for your contribution and I apologize for a late response.
Please also take a look at the review comments from copilot and resolve them if possible.
| } | ||
| if radix != 10 { | ||
| return BigInt::from_string_radix(input, radix) | ||
| let input = str.to_owned() |
There was a problem hiding this comment.
This creates a copy of the string, which seems unnecessary here.
| } | ||
| if str == "-" { | ||
| abort("invalid character") | ||
| let input = str.to_owned() |
| } | ||
|
|
||
| // Values | ||
| pub fn parse_bigint(StringView, base? : Int) -> BigInt raise |
There was a problem hiding this comment.
I don't think we should add a new API. Instead, we could deprecate BigInt::from_string and encourage users to use @strconv.parse_bigint instead.
|
Thanks for the review @Yu-zh I've addressed your comments: Removed unnecessary Moved the user-facing API out of
Also merged latest Could you take another look when you have time? Thanks! |
38c83fe to
b5c8f8b
Compare
|
@rainhuang0220 Sorry again for delayed response. We have reverted the unnecessary changes to the strconv package (my bad for suggesting it) and fixed a regression problem. Now this PR is good to merge. |
Co-authored-by: Cursor <cursoragent@cursor.com>
67d6f5e to
256e4db
Compare
Summary
@string.parse_bigintwith raising error handlingBigInt::from_stringpanic behavior for compatibilityBigInt::from_jsonto useparse_bigintFixes [Consistency Review] BigInt::from_string should raise or add a @string.parse_bigint #3566
Test plan
moon test -p bigint -p stringmoon check bigint string --deny-warn