Skip to content

Commit 664cd26

Browse files
cmd/vet: don't exit with failure on type checking error
The vet tool only reports a type checking error when invoked with -v. Don't let that by itself cause vet to exit with an error exit status. Updates #21188 Change-Id: I172c13d46c35d49e229e96e833683d8c82a77de7 Reviewed-on: https://go-review.googlesource.com/52851 Reviewed-by: Josh Bleecher Snyder <[email protected]> Reviewed-by: Rob Pike <[email protected]>
1 parent a8730cd commit 664cd26

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/cmd/vet/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,9 @@ func doPackage(directory string, names []string, basePkg *Package) *Package {
349349
pkg.files = files
350350
// Type check the package.
351351
err := pkg.check(fs, astFiles)
352-
if err != nil && *verbose {
353-
warnf("%s", err)
352+
if err != nil {
353+
// Note that we only report this error when *verbose.
354+
Println(err)
354355
}
355356

356357
// Check.

src/cmd/vet/testdata/cgo/cgo3.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Used by TestVetVerbose to test that vet -v doesn't fail because it
6+
// can't find "C".
7+
8+
package testdata
9+
10+
import "C"
11+
12+
func F() {
13+
}

src/cmd/vet/vet_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,15 @@ func TestTags(t *testing.T) {
205205
})
206206
}
207207
}
208+
209+
// Issue #21188.
210+
func TestVetVerbose(t *testing.T) {
211+
t.Parallel()
212+
Build(t)
213+
cmd := exec.Command("./"+binary, "-v", "-all", "testdata/cgo/cgo3.go")
214+
out, err := cmd.CombinedOutput()
215+
if err != nil {
216+
t.Logf("%s", out)
217+
t.Error(err)
218+
}
219+
}

0 commit comments

Comments
 (0)