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
Does this issue reproduce with the latest release?
yes
What did you do?
package main
import "time"
type T struct {
time.Time
}
var a map[T]string
func main() {
}
$ go vet a.go
$ [nothing reported]
What did you expect to see?
$ go vet a.go
$ time.Time is not a good map key type.
Like time.Time, there may be some other types, which are not capable to be used as map key types.
What did you see instead?
nothing reported
The text was updated successfully, but these errors were encountered:
zigo101
changed the title
go vet: vet should warn on struct types which embed time.Time when the struct types are used as map keys.
go vet: vet should warn when time.Time type (or types embed it) is used as map keys.
Dec 4, 2017
It's perfectly valid to use a time.Time as a map key, if you know what you're doing. I think it would be too noisy for valid code.
But somebody could do some analysis on GitHub to see what percentage of time.Time-keyed maps are valid.
bradfitz
changed the title
go vet: vet should warn when time.Time type (or types embed it) is used as map keys.
proposal: cmd/vet: vet should warn when time.Time type (or types embed it) is used as map keys.
Dec 4, 2017
Now that vet is part of go test, the bar is even higher for new checks. Because it is valid sometimes to have a time.Time as a map key, rejecting it in vet is not OK.
You might talk to @dominikh about adding this to megacheck or one of the other linters.
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
Does this issue reproduce with the latest release?
yes
What did you do?
What did you expect to see?
Like time.Time, there may be some other types, which are not capable to be used as map key types.
What did you see instead?
nothing reported
The text was updated successfully, but these errors were encountered: