Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[checklocks] Annotations ignored on generic structs #10372

Open
rodaine opened this issue May 3, 2024 · 0 comments
Open

[checklocks] Annotations ignored on generic structs #10372

rodaine opened this issue May 3, 2024 · 0 comments
Assignees
Labels
area: nogo type: bug Something isn't working

Comments

@rodaine
Copy link

rodaine commented May 3, 2024

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
@rodaine rodaine added the type: bug Something isn't working label May 3, 2024
@milantracy milantracy self-assigned this May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: nogo type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants