cmd/vet: decide how to handle type checking failure #21287
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
People rarely ran vet with the
https://golang.org/cl/40112 (pre-1.9) changed cmd/go to pass more flags to vet. In particular, after that change,
This led to issue #21188 complaining that
https://golang.org/cl/52851 (also pre-1.9) changed cmd/vet so that a type checking error just prints a message with
How do we want to handle this going forward?
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
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.
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 <firstname.lastname@example.org>