-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.Issue is not actionable because of missing required information, which needs to be provided.v2An incompatible library changeAn incompatible library change
Milestone
Description
What version of Go are you using (go version
)?
$ go version 1.14.1
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env
)?
I don't think this is relevant.
What did you do?
I tried to use byte slices in a context where they might be compared (most notably, as fields in a struct which is a map key).
What did you expect to see?
Considering #31587, byte slices are as comparable as strings are and the comparison does not allocate. Therefore, I would expect them to be comparable like strings and acceptable as members of a struct used as a map key.
What did you see instead?
Byte slices are not comparable while strings are.
- Using
bytes.Equal
instead of==
for comparing byte slices is merely a syntactic nuisance. - So is using byte slices as keys in a map via
string(b)
. - However the current behavior means that it is not possible to use a struct containing byte slices as a map key whereas it is possible to use a struct containing strings as a map key. This leads to hacks converting one type to another or using less intuitive solutions altogether which provide no benefit over
[]byte
being comparable as-is.
It doesn't seem to me that changing this would break backwards compatibility/any code out there as currently it is not possible to use a []byte
in a comparable type context at all.
Also, the invalid map key type fnord
error message could be more helpful.
BrianLeishmanbitfield, tv42 and davecheney
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.Issue is not actionable because of missing required information, which needs to be provided.v2An incompatible library changeAn incompatible library change