[checklocks] Annotations ignored on generic structs
rodaine opened this issue · comments
Chris Roche commented
Description
It appears checklocks
(sha: 69e0c7643d821f03ed797ea3911f6ab458e2a2d6
) fails to recognize annotations on generic types. For the following code:
package example
import (
"sync"
)
type X struct {
mu sync.Mutex
// +checklocks:mu
m map[string]struct{}
}
func (x *X) Add(k string) {
x.mu.Lock()
defer x.mu.Unlock()
x.m[k] = struct{}{}
}
type Y[K comparable] struct {
mu sync.Mutex
// +checklocks:mu
m map[K]struct{}
}
func (y *Y[K]) Add(k K) {
y.mu.Lock()
defer y.mu.Unlock()
y.m[k] = struct{}{}
}
checklocks
returns the following:
$ go version
go version go1.22.2 darwin/arm64
$ go vet -vettool=.bin/checklocks ./example/...
# example.com/example
example/x.go:22:2: may require checklocks annotation for mu, used with lock held 100% of the time