-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
[]int32 and []rune cannot exist in the same type switch #27955
Comments
This is working as documented. The type This program prints OK: https://play.golang.org/p/RGZNdC7pclA . |
@ianlancetaylor then can the reference be updated to state that |
@valarauca Which reference are you referring to? |
The language reference specification link which states:
As So if this could be changed to:
Also a note should be added that compile time type easure between |
Lastly should I open an issue that fmt.Printf("Type: %T\n", rune('a')) Prints that seems like an error? |
I don't think your suggested rewrite is correct. A rune literal, which is one or more characters written within single quotes, is a Unicode point. And a rune literal has type Similarly, your |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.11 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?What did you do?
int32
andrune
collide with one-another in type reflectionhttps://play.golang.org/p/gXKj4J2OuA5
Furthermore
[]int32
and[]rune
collide with one-anotherhttps://play.golang.org/p/63ZrNkv3VEa
What did you expect to see?
In short
[]int32
and[]rune
should both be able to exist within a type switch. According to the specification arune
is a Unicode Code Point. So[]rune
should be extremely restricted to which values it can hold, and in what order. As according to the Unicode consortium not allin32
are validrune
.When writing something to accept
interface{}
, such a logger. Being able to distinguish between[]rune
and[]int32
when accepting a message, or key-value to populate with a log message. Is rather important as these arguments will formatted vastly different.[]rune
can likely be formatted astring
, while[]int32
should formatted as[ a, b, c, d]
to pleasantly present a list of values.In short either the reference should state
rune
is just an alias ofint32
, and has no special meaning. Or the compiler should enforce the special meaning given in the reference.What did you see instead?
A Compiler Error.
The text was updated successfully, but these errors were encountered: