You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for i := rune(0); i < 8; i++ works too.
It is planned that the feature of converting non-rune and none-byte integers to strings will be removed from a future Go version.
In future, it will be illegal to convert an int to a string this way, as it has led to too much misunderstanding. People accustomed to other languages often expect string(3) to yield "3", but in Go the result instead is "\x03", which can be surprising. Still converting a rune to a one-rune string makes perfect sense.
The decision was therefore made to transition to making that illegal by having vet complain about conversions from integer types other than runes.
This is working as intended. If the argument to string is a rune, the problem goes away, as you observed.
@opennota I think @robpike gave a very good explanation. I think the confusion may be caused by an unclear vet message. I am happy to consider improving the messages from vet if you have a suggestion.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/EW1W9iTRyK9
What did you expect to see?
No errors from go vet.
What did you see instead?
conversion from int to string yields a string of one rune, not a string of digits (did you mean fmt.Sprint(x)?)
It it clear from the code I do indeed need a string of one rune, not a string of digits.
The text was updated successfully, but these errors were encountered: