Skip to content

Commit 76dc4b1

Browse files
committed
cmd/go: ignore vet typecheck failure during go test
For Go 1.10, works around a go/types bug that can't typecheck a corner-case type cycle. Once we are confident that bugs like this are gone from go/types then we can stop ignoring these failures. For #22890. Change-Id: I38da57e01a0636323e1af4484c30871786125df3 Reviewed-on: https://go-review.googlesource.com/81500 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 2f8bcc8 commit 76dc4b1

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/cmd/go/go_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5115,6 +5115,9 @@ func TestTestVet(t *testing.T) {
51155115
tg.grepStdout(`\[no test files\]`, "did not print test summary")
51165116
tg.run("test", "-vet=off", filepath.Join(tg.tempdir, "p1.go"))
51175117
tg.grepStdout(`\[no test files\]`, "did not print test summary")
5118+
5119+
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
5120+
tg.run("test", "vetcycle") // must not fail; #22890
51185121
}
51195122

51205123
func TestInstallDeps(t *testing.T) {

src/cmd/go/internal/work/exec.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ type vetConfig struct {
638638
GoFiles []string
639639
ImportMap map[string]string
640640
PackageFile map[string]string
641+
642+
SucceedOnTypecheckFailure bool
641643
}
642644

643645
// VetFlags are the flags to pass to vet.
@@ -663,6 +665,13 @@ func (b *Builder) vet(a *Action) error {
663665
vcfg.PackageFile["fmt"] = a1.built
664666
}
665667

668+
// During go test, ignore type-checking failures during vet.
669+
// We only run vet if the compilation has succeeded,
670+
// so at least for now assume the bug is in vet.
671+
// We know of at least #18395.
672+
// TODO(rsc,gri): Try to remove this for Go 1.11.
673+
vcfg.SucceedOnTypecheckFailure = cfg.CmdName == "test"
674+
666675
js, err := json.MarshalIndent(vcfg, "", "\t")
667676
if err != nil {
668677
return fmt.Errorf("internal error marshaling vet config: %v", err)

src/cmd/go/testdata/src/vetcycle/p.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package p
2+
3+
4+
type (
5+
_ interface{ m(B1) }
6+
A1 interface{ a(D1) }
7+
B1 interface{ A1 }
8+
C1 interface{ B1 /* ERROR issue #18395 */ }
9+
D1 interface{ C1 }
10+
)
11+
12+
var _ A1 = C1 /* ERROR cannot use C1 */ (nil)

src/cmd/vet/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var (
3535
tagList = []string{} // exploded version of tags flag; set in main
3636

3737
mustTypecheck bool
38+
39+
succeedOnTypecheckFailure bool // during go test, we ignore potential bugs in go/types
3840
)
3941

4042
var exitCode = 0
@@ -291,6 +293,8 @@ type vetConfig struct {
291293
ImportMap map[string]string
292294
PackageFile map[string]string
293295

296+
SucceedOnTypecheckFailure bool
297+
294298
imp types.Importer
295299
}
296300

@@ -336,6 +340,7 @@ func doPackageCfg(cfgFile string) {
336340
if err := json.Unmarshal(js, &vcfg); err != nil {
337341
errorf("parsing vet config %s: %v", cfgFile, err)
338342
}
343+
succeedOnTypecheckFailure = vcfg.SucceedOnTypecheckFailure
339344
stdImporter = &vcfg
340345
inittypes()
341346
mustTypecheck = true
@@ -427,6 +432,9 @@ func doPackage(names []string, basePkg *Package) *Package {
427432
// Type check the package.
428433
errs := pkg.check(fs, astFiles)
429434
if errs != nil {
435+
if succeedOnTypecheckFailure {
436+
os.Exit(0)
437+
}
430438
if *verbose || mustTypecheck {
431439
for _, err := range errs {
432440
fmt.Fprintf(os.Stderr, "%v\n", err)

0 commit comments

Comments
 (0)