strconv: parse_int and parse_uint accept underscores for an explicit base
Maintainers usually reply within 1 day
A pull request for this has already been merged.
- #29962 by @medvednikov — merged
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend
Research direction
The bug is in the underscore branch of the shared digit loop in atoi.v (around lines 89-100), which the doc comment at lines 217-218 says should apply only when base is 0. Read that loop first, then check the base-0 tests in atoi_test.v (lines 449-478) and the explicit-base tests (lines 404-447). Done when gating the underscore branch on base == 0 makes parse_int("1_000", 10, 0) return a syntax error, and the existing base-0 tests still pass.
Written by the indexing model from the issue text.
Description
Go permits underscore digit separators only when the base is 0. V accepts them for any base.
// V 0.5.2 5bd6709
parse_int("1_000", 10, 0) = 1000
parse_int("1_000", 10, 64) = 1000
parse_uint("1_000", 10, 0) = 1000
parse_int("ff_ff", 16, 0) = 65535
parse_int("0x1_0", 0, 0) = 16 // base 0: both agree, this is correct
// Go 1.26.1
ParseInt("1_000", 10, 0) -> invalid syntax
ParseInt("1_000", 10, 64) -> invalid syntax
ParseUint("1_000", 10, 0) -> invalid syntax
ParseInt("ff_ff", 16, 0) -> invalid syntax
ParseInt("0x1_0", 0, 0) -> 16, nil
The parse_int doc comment (atoi.v:217-218) already states the Go rule: "for argument base 0 only, underscore characters are permitted". The base-0 case works and is tested — atoi_test.v:449-478 pins '0_10' == 8 and '07_7' == 63 — but the underscore branch at atoi.v:89-100 sits inside the shared digit loop and is not gated on the base, so an explicit base gets the separator the doc says it should not have.
atoi_test.v:404-447 looks like it pins the behaviour for all bases, but line 443 calls common_parse_uint(query[0], 0, 32, ...) — base 0 — so it does not cover this.
Gating the branch on base == 0 sends 1_000 down the existing non-digit path, which already produces the right error: parse_int("1 000", 10, 0) returns a syntax error today through that same mechanism.
Measured on V 0.5.2 5bd6709 (tree 5bd67093f9), Go 1.26.1, Windows 11 x64. No patch attached.
- Dominant language
- V
- Stars
- 38.1k
- Forks
- 2.3k
- Avg merge
- 15h 8m
- Merged PRs (30d)
- 839
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vlang/v
-
Bug
Difficulty 3/5 1-2 days Newbie friendliness 58/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
compress.szip / compress.deflate: compression levels, bounded reading, ZIP64 and entry metadataPossibly taken @davlgd claimed this today. Open
Difficulty 5/5 Over a week Newbie friendliness 8/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 22/100
Maintainers usually reply within 1 day
-
The compiler keeps using the old template after a `$tmpl` file changesPossibly taken @metif12 claimed this today. OpenBug
Difficulty 3/5 Half a day Newbie friendliness 45/100
Maintainers usually reply within 1 day
Similar issues
-
Text to Speech fails on Windows: the temp file path loses its backslashes when stored in post metaPossibly taken @azizulhasan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ballerina-platform/ballerina-library#9458 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
OneBusAway/maglev#1914 ·
Maintainers usually reply within 2 days
-
Slack: DM thread replies sent with "Also send to..." never reach the agentPossibly taken @roboeve claimed this today. Openbug channel:slack p2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
vercel/eve#5774 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
sususweet/midea_auto_cloud#284 ·
Maintainers usually reply within 1 day