Commit 76dc4b19 authored by Russ Cox's avatar Russ Cox

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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 2f8bcc89
...@@ -5115,6 +5115,9 @@ func TestTestVet(t *testing.T) { ...@@ -5115,6 +5115,9 @@ func TestTestVet(t *testing.T) {
tg.grepStdout(`\[no test files\]`, "did not print test summary") tg.grepStdout(`\[no test files\]`, "did not print test summary")
tg.run("test", "-vet=off", filepath.Join(tg.tempdir, "p1.go")) tg.run("test", "-vet=off", filepath.Join(tg.tempdir, "p1.go"))
tg.grepStdout(`\[no test files\]`, "did not print test summary") 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) { func TestInstallDeps(t *testing.T) {
......
...@@ -638,6 +638,8 @@ type vetConfig struct { ...@@ -638,6 +638,8 @@ type vetConfig struct {
GoFiles []string GoFiles []string
ImportMap map[string]string ImportMap map[string]string
PackageFile map[string]string PackageFile map[string]string
SucceedOnTypecheckFailure bool
} }
// VetFlags are the flags to pass to vet. // VetFlags are the flags to pass to vet.
...@@ -663,6 +665,13 @@ func (b *Builder) vet(a *Action) error { ...@@ -663,6 +665,13 @@ func (b *Builder) vet(a *Action) error {
vcfg.PackageFile["fmt"] = a1.built 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") js, err := json.MarshalIndent(vcfg, "", "\t")
if err != nil { if err != nil {
return fmt.Errorf("internal error marshaling vet config: %v", err) return fmt.Errorf("internal error marshaling vet config: %v", err)
......
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)
...@@ -35,6 +35,8 @@ var ( ...@@ -35,6 +35,8 @@ var (
tagList = []string{} // exploded version of tags flag; set in main tagList = []string{} // exploded version of tags flag; set in main
mustTypecheck bool mustTypecheck bool
succeedOnTypecheckFailure bool // during go test, we ignore potential bugs in go/types
) )
var exitCode = 0 var exitCode = 0
...@@ -291,6 +293,8 @@ type vetConfig struct { ...@@ -291,6 +293,8 @@ type vetConfig struct {
ImportMap map[string]string ImportMap map[string]string
PackageFile map[string]string PackageFile map[string]string
SucceedOnTypecheckFailure bool
imp types.Importer imp types.Importer
} }
...@@ -336,6 +340,7 @@ func doPackageCfg(cfgFile string) { ...@@ -336,6 +340,7 @@ func doPackageCfg(cfgFile string) {
if err := json.Unmarshal(js, &vcfg); err != nil { if err := json.Unmarshal(js, &vcfg); err != nil {
errorf("parsing vet config %s: %v", cfgFile, err) errorf("parsing vet config %s: %v", cfgFile, err)
} }
succeedOnTypecheckFailure = vcfg.SucceedOnTypecheckFailure
stdImporter = &vcfg stdImporter = &vcfg
inittypes() inittypes()
mustTypecheck = true mustTypecheck = true
...@@ -427,6 +432,9 @@ func doPackage(names []string, basePkg *Package) *Package { ...@@ -427,6 +432,9 @@ func doPackage(names []string, basePkg *Package) *Package {
// Type check the package. // Type check the package.
errs := pkg.check(fs, astFiles) errs := pkg.check(fs, astFiles)
if errs != nil { if errs != nil {
if succeedOnTypecheckFailure {
os.Exit(0)
}
if *verbose || mustTypecheck { if *verbose || mustTypecheck {
for _, err := range errs { for _, err := range errs {
fmt.Fprintf(os.Stderr, "%v\n", err) fmt.Fprintf(os.Stderr, "%v\n", err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment