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
strconv: document exact grammar of Parse{Float,Int,Uint} #31197
Comments
The proposed Go 1.13 number literal changes are language changes, obviously the accepted grammar of the respective strconv routines had to be adjusted. Though for the integer parsing functions, the more flexible grammar (underscores) is only permitted if the Well-formed here does mean it follows the Go language spec for these literals. |
@andybons, I'm a little confused. Is there a reason this is marked as a proposal?
The fact that
Behavior of like this is surprising and all the more shows that the documentation around these functions is lacking. |
@dsnet I've been imprecise: The integer parse routines, if they specify a non-zero base, do not follow the language spec (since the language spec doesn't pemit, say a hex literal without the In any case, this shouldn't be a proposal (I fixed that). This is a just a documentation issue. |
Change https://golang.org/cl/191078 mentions this issue: |
Fixes #33750. Updates #31197. Change-Id: I26f63cef57e5f0eec85b84554c82f6d47b4f41a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/191078 Reviewed-by: Robert Griesemer <gri@golang.org>
Change https://golang.org/cl/191168 mentions this issue: |
Fixes #33750. Updates #31197. Change-Id: I26f63cef57e5f0eec85b84554c82f6d47b4f41a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/191078 Reviewed-by: Robert Griesemer <gri@golang.org> (cherry picked from commit d9b1323) Reviewed-on: https://go-review.googlesource.com/c/go/+/191168 Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Fixes golang#33750. Updates golang#31197. Change-Id: I26f63cef57e5f0eec85b84554c82f6d47b4f41a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/191078 Reviewed-by: Robert Griesemer <gri@golang.org>
strconv.Parse{Float,Int,Uint}
is frequently used in the implementation of other grammars (e.g., JSON), which may be a subset or superset of whatstrconv.ParseX
currently does today. However, whatstrconv.Parse
does today is not well-specified. What exactly is the input grammar that is accepted?For example, the documentation for
ParseFloat
only says "If s is well-formed", but does not specify what "well-formed" means. I suspect that the answer to this is whether the input is well-formed according to the grammar in the Go specification. If so, this needs to be documented.Furthermore, this also opens the question for whether the input grammar is stable. Apparently, this is not the case since
strconv.ParseX
was recently augmented to support the new number literal grammars (CL/160241 and CL/160244). This change is going to silently break a number of use-cases that were assuming that the input ofParseX
was constrained to the grammar prior to Go1.13. If so, the instability of the input grammar should also be documented.(BTW, I think the change in semantics is entirely reasonable and I support it; but I see a lot of code silently broken by this change. Documenting this better would help dissuade future abuse.)
\cc @cybrcodr, @griesemer, @rsc
The text was updated successfully, but these errors were encountered: