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
cmd/vet: flag atomic.Value usages with interface types #22550
Comments
The support in this CL assumes that something at a higher level than the toolchain-specific importers is taking care of converting imports in source code into canonical import paths before invoking the toolchain-specific importers. That kind of "what does an import mean" as opposed to "find me the import data for this specific path" should be provided by higher-level layers. That's a different layering than the default behavior but matches the current layering in the compiler and linker and works with the metadata planned for generation by the go command for package management. It should also eventually allow the importer code to stop concerning itself with source directories and vendor import translation and maybe deprecate ImporterFrom in favor of Importer once again. But that's all in the future. For now, just make non-nil lookups work, and test that. Fixes golang#13847. Adds golang#22550. Change-Id: I048c6a384492e634988a7317942667689ae680ff Reviewed-on: https://go-review.googlesource.com/74354 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Deleted an incorrect reference from a CL to help others avoid the confusion it caused me. I suspect the frequency is very low, and since the runtime catches the error anyway, and is likely to do so the first time the program is run, some convincing is required. |
/cc @mvdan @alandonovan |
Seems very obscure. atomic.Value is not an everyday or (everyyear) thing. |
Here's a self-contained reproducer: https://play.golang.org/p/mM_n7IQFJ0p I am also unsure that this passes the frequency requirement. I've only used I've also quickly put together a gogrep query to find these, and to verify that
Perhaps the query can be used on a large corpus of Go code, to check if any matches would be found. |
Consider the following:
The intention to have a atomic value store for errors. However, running this code panics:
This is because
atomic.Value
requires that the underlying concrete type be the same (which is a reasonable expectation for its implementation). When going through theatomic.Value.Store
method call, the fact that both these are of theerror
interface is lost.Perhaps we should add a vet check that flags usages of
atomic.Value
where the argument passed in is an interface type?Vet criterions:
\cc @robpike
\cc @dominikh for
staticcheck
The text was updated successfully, but these errors were encountered: