Closed
Description
Please answer these questions before submitting your issue. Thanks!
- What version of Go are you using (
go version
)?
go version go1.6 darwin/amd64 - What operating system and processor architecture are you using (
go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ryangao/go"
GORACE=""
GOROOT="/Users/ryangao/homebrew/Cellar/go/1.6/libexec"
GOTOOLDIR="/Users/ryangao/homebrew/Cellar/go/1.6/libexec/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1" - What did you do?
Run "go vet" on code from https://play.golang.org/p/mUiuNfZDHT - What did you expect to see?
Expect "go vet" warns about error mentioned in
https://golang.org/doc/faq#closures_and_goroutines - What did you see instead?
No warning issued.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
rsc commentedon Oct 20, 2016
This does seem like it would catch real problems if done well.
/cc @adonovan
rsc commentedon Oct 20, 2016
Actually, note that those captures - at least when they are definite bugs - should usually show up in the race detector. It's not clear vet can contribute more than the race detector does without significant false positives.
alandonovan commentedon Oct 20, 2016
Although this bug pattern most often manifests with
go
statements (leading to data races), sequential (non-racy) instances are possible too, such as withdefer
or the simple example presented in this Issue.vet already checks for patterns of the form:
The example presented in this Issue is more challenging to analyze because it requires proving that the function is not called within the loop, or at least failing to prove that it is called within the loop. Once the anonymous function has been stored in a data structure or passed to another function, vet can no longer precisely determine when it might be called.
In other words, I think the current vet check is probably as good as we can do without interprocedural analysis.
53 remaining items
gopherbot commentedon Dec 5, 2022
Change https://go.dev/cl/455195 mentions this issue:
go/analysis/passes/loopclosure: allow certain well-understood statements to trail problematic go and defer statements
dmitris commentedon Feb 29, 2024
Is this no longer relevant with go1.22 / should be closed? @adonovan
timothy-king commentedon Feb 29, 2024
Yep. It is fine to close this with the 1.22 lifetime rules.
zigo101 commentedon Feb 7, 2025
ianlancetaylor commentedon Feb 8, 2025
zigo101 commentedon Feb 8, 2025
zigo101 commentedon Feb 11, 2025