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
spec: inconsistency about allowable conversions of numeric constants to strings #24745
Comments
Somewhat related: #21982. |
This suggests in the code below that
However, cmd/compile and go/types both give |
doesn't integer constants include rune constants? |
I also think 'x' is an integer constant. It's just its default type is |
|
I think that |
That's not what the Go spec says (emphasis added):
Rune constants are integer values, but not integer constants. |
I agree with @mdempsky that there is at least some imprecision if not inconsistency in the spec in this area. We use mildly similar terminology for different purposes (integer value vs integer constant vs integer vs int type, etc.) and these terms are vaguely defined if at all. I think we need to clearly define these terms in one place (consistent with existing use) and then this issue (and related ones) should become clear. |
In section "Conversions", the Go spec says:
Note that "integer constants" are distinct from "rune constants", "float constants", etc.
However, the spec also includes two examples of conversions of rune literals to type string:
string('x')
andstring('a')
.cmd/compile and go/types allow these conversions. I assume gccgo does too, as utf8.RuneError is an untyped rune constant, and
string(utf8.RuneError)
appears a few times in the standard library.I think the wording should be tweaked to "an integer or rune constant x".
Aside: I'd think we should relax it further to allow any integer value. We allow
make([]byte, 1.0)
, so it seems inconsistent to not allowstring(1.0)
./cc @griesemer
The text was updated successfully, but these errors were encountered: