-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: decide how to handle type checking failure #21287
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
Thanks for the thorough explanation of the history of the issue, Ian.
Something to add is #6774 - eventually, the
I strongly believe this is a bad idea, because it's counter-intuitive. It's also worth noting that since |
@robpike cc'ing myself. |
I suggested we check in the CL that restores prior behavior, however awkwardly, and then address this in 1.10. It does not need to be a release blocker. |
https://go-review.googlesource.com/c/go/+/74356 is for #18084 but the idea was to also hook it up to #16086, so that when run as "go vet", vet can expect that it will have complete type information and no magic import "C" to worry about. Then it should be a fatal error in that mode for vet to fail to typecheck. So the decision here is "go vet" will be fixed so that it can always typecheck, and then failure to typecheck will be a fatal error. Given that decision, this is a duplicate of #16086. |
Change https://golang.org/cl/121455 mentions this issue: |
Since Go1.10, go test runs vet on the tests before executing them. Moreover, the vet tool typechecks the package under analysis with go/types before running. In Go1.10, a typechecking failure just caused a warning to be printed. In Go1.11, a typechecking failure will cause vet to exit with a fatal error (see Issue #21287). This means that starting with Go1.11, tests that don't typecheck will fail immediately. This would not normally be an issue, since a test that doesn't typecheck shouldn't even compile, and it should already be broken. Unfortunately, there's a bug in gc that makes it accept programs with unused variables inside a closure (Issue #3059). This means that a test with an unused variable inside a closure, that compiled and passed in Go1.10, will fail in the typechecking step of vet starting with Go1.11. Explain this in the 1.11 release notes. Fixes #26109 Change-Id: I970c1033ab6bc985d8c64bd24f56e854af155f96 Reviewed-on: https://go-review.googlesource.com/121455 Reviewed-by: Ian Lance Taylor <[email protected]>
This issue is to decide how cmd/vet should handle type checking failures.
In https://golang.org/cl/7393052 (pre-1.1) type checking was added to cmd/vet. A type checking error would issue a warning and cause vet to exit with status 1.
Issue #4895 complained about this behavior, because it meant that the type checker had to be able to find imported packages. In that issue Russ said "It would definitely be nice for 'go vet' to be able to run in degraded mode. I ran it on a large uncompiled tree over the weekend and was pretty annoyed by all the import messages."
https://golang.org/cl/7399051 (also pre-1.1) addressed this problem by only issuing the warning, and setting the exit status, if vet were run with the
-v
option.People rarely ran vet with the
-v
option, because there was no way to do so when usinggo vet
; it could only be done by usinggo tool vet
.https://golang.org/cl/40112 (pre-1.9) changed cmd/go to pass more flags to vet. In particular, after that change,
go vet -v
invoked cmd/vet with the-v
option.This led to issue #21188 complaining that
go vet -v
now caused unexpected errors when a package was not available (for example, the special "C" package used by cgo). This was essentially a repeat of #4895, only with the-v
option that is now easier to use.https://golang.org/cl/52851 (also pre-1.9) changed cmd/vet so that a type checking error just prints a message with
-v
, rather than issuing a warning and thus changing the exit status to 1.How do we want to handle this going forward?
CC @robpike
The text was updated successfully, but these errors were encountered: