]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: ignore vet typecheck failure during go test
authorRuss Cox <rsc@golang.org>
Fri, 1 Dec 2017 17:17:37 +0000 (12:17 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 1 Dec 2017 21:06:03 +0000 (21:06 +0000)
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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/work/exec.go
src/cmd/go/testdata/src/vetcycle/p.go [new file with mode: 0644]
src/cmd/vet/main.go

index e37352bba971bbb5f81c90ef9f5fb95fe669b940..691945b9efc1d6927324db88bc583d551ed1a770 100644 (file)
@@ -5115,6 +5115,9 @@ func TestTestVet(t *testing.T) {
        tg.grepStdout(`\[no test files\]`, "did not print test summary")
        tg.run("test", "-vet=off", filepath.Join(tg.tempdir, "p1.go"))
        tg.grepStdout(`\[no test files\]`, "did not print test summary")
+
+       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+       tg.run("test", "vetcycle") // must not fail; #22890
 }
 
 func TestInstallDeps(t *testing.T) {
index 2e170fa040ade0d17dd93e1ee62716c1c1890973..43409de764fba5d9ef2adad3d838789f6840a0f6 100644 (file)
@@ -638,6 +638,8 @@ type vetConfig struct {
        GoFiles     []string
        ImportMap   map[string]string
        PackageFile map[string]string
+
+       SucceedOnTypecheckFailure bool
 }
 
 // VetFlags are the flags to pass to vet.
@@ -663,6 +665,13 @@ func (b *Builder) vet(a *Action) error {
                vcfg.PackageFile["fmt"] = a1.built
        }
 
+       // During go test, ignore type-checking failures during vet.
+       // We only run vet if the compilation has succeeded,
+       // so at least for now assume the bug is in vet.
+       // We know of at least #18395.
+       // TODO(rsc,gri): Try to remove this for Go 1.11.
+       vcfg.SucceedOnTypecheckFailure = cfg.CmdName == "test"
+
        js, err := json.MarshalIndent(vcfg, "", "\t")
        if err != nil {
                return fmt.Errorf("internal error marshaling vet config: %v", err)
diff --git a/src/cmd/go/testdata/src/vetcycle/p.go b/src/cmd/go/testdata/src/vetcycle/p.go
new file mode 100644 (file)
index 0000000..857c3a6
--- /dev/null
@@ -0,0 +1,12 @@
+package p
+
+
+type (
+       _ interface{ m(B1) }
+       A1 interface{ a(D1) }
+       B1 interface{ A1 }
+       C1 interface{ B1 /* ERROR issue #18395 */ }
+       D1 interface{ C1 }
+)
+
+var _ A1 = C1 /* ERROR cannot use C1 */ (nil)
index 66f9449d7e03bd9df718a6019a1a80452191508c..a10c79885040634ea590299768aa3a7ace511bb5 100644 (file)
@@ -35,6 +35,8 @@ var (
        tagList = []string{} // exploded version of tags flag; set in main
 
        mustTypecheck bool
+
+       succeedOnTypecheckFailure bool // during go test, we ignore potential bugs in go/types
 )
 
 var exitCode = 0
@@ -291,6 +293,8 @@ type vetConfig struct {
        ImportMap   map[string]string
        PackageFile map[string]string
 
+       SucceedOnTypecheckFailure bool
+
        imp types.Importer
 }
 
@@ -336,6 +340,7 @@ func doPackageCfg(cfgFile string) {
        if err := json.Unmarshal(js, &vcfg); err != nil {
                errorf("parsing vet config %s: %v", cfgFile, err)
        }
+       succeedOnTypecheckFailure = vcfg.SucceedOnTypecheckFailure
        stdImporter = &vcfg
        inittypes()
        mustTypecheck = true
@@ -427,6 +432,9 @@ func doPackage(names []string, basePkg *Package) *Package {
        // Type check the package.
        errs := pkg.check(fs, astFiles)
        if errs != nil {
+               if succeedOnTypecheckFailure {
+                       os.Exit(0)
+               }
                if *verbose || mustTypecheck {
                        for _, err := range errs {
                                fmt.Fprintf(os.Stderr, "%v\n", err)