-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: vet is reporting lock value copying because of a Lock method unrelated to mutexes #18451
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
Comments
vet checks for any /cc @robpike |
This is related to #8005, which made the decision to embed a |
Ah, okay. Thanks for the context. |
It doesn't check for From this issue report, it seems that there are types with |
For history, this decision was from Rob's comment on the original copylocks vet CL. This is the first complaint about this in three years, and having Lock == "no copy" was actually a really useful solution to #8005, so I think it is worth understanding a bit more before altering this. @dlecorfec can you provide some context about what Lock means in your program? |
I see. From what I understand, Set A = all types that transitively embed cmd/vet should warn on A. But it uses B as a proxy for A, and ends up warning for types in B-A set too. How difficult is it to determine whether type T transitively embeds type V? If it's not difficult, we should do that. Otherwise, leave it as is on the ground of this being infrequent false-positive. |
I'd like understand more about the original program first: what does the
original Lock method do? Why is it ok to copy? Without a concrete example,
this issue seems pretty hypothetical.
Perhaps the problem is not in cmd/vet but the design of the Lock method.
|
Context: a Job struct (for a video encoding job), with a Lock() method which inserts a SQL row in a video_encoding_lock table in order to prevent multiple workers (on multiple servers) from processing the same job. Notwithstanding this possibly dubious architecture (legacy stuff, slightly older than Go itself), I can easily rename this method if this cmd/vet behaviour is intended. Being new to this video code base, I was confused by the warning because the struct didn't contain a mutex and I didn't see its Lock method at first sight :) |
Thanks, @dlecorfec. The lock is external, making it ok to copy; makes sense. I think that we should take this as a data point, recommend renaming the Lock method for now, and wait to see whether this issue arises again. |
Agree with @josharian. Good data point, but for now you need to rename your Lock method. Sorry. |
Done, no problem, thanks all for your time! |
go version go1.7.3 linux/amd64
A method named Lock() on a struct is enough to trigger the vet lock copy warning. See https://play.golang.org/p/V2v2w7DPAM
What did you expect to see?
$ go vet
$
What did you see instead?
$ go vet
main.go:11: assignment copies lock value to b: main.A
main.go:12: assignment copies lock value to _: main.A
exit status 1
$
The text was updated successfully, but these errors were encountered: