Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
spec: legal conversions from string constant to byte slice are not covered by convertability rules #25991
According to Conversions (as of 21.06.2018), the following programs should be illegal, but it compiles without errors:
Here we have constant value
The assumption above contradicts with Assignability rules. Consider the following program that fails to compile:
Did you miss the https://golang.org/ref/spec#Conversions_to_and_from_a_string_type section?
Yes, this is the part that covers it, thanks.
However, this is what Conversions section says for constant values:
As you can see, conversion from integer constant to string is noted as a special case and is governed by the rules for non-constant x. These rules are described in the section that I missed (Conversions to and from a string type).
But that makes me think that the Conversions to and from a string type is for non-constant values. The section itself does not state explicitly what values the rules are applied to. As a result, it is not obvious that I should consult that section when working with constant values.
Moreover, Conversions section contains the following note:
Again, as far as I can see it is about Conversions to and from a string type.