From ffe88906718454e356e61776b54256e873fc133b Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 2 Jul 2018 14:44:56 +1000 Subject: [PATCH] cmd/stringer: revert CL 40403 Revert "cmd/stringer: use source importer when available" This reverts CL 40403. The idea is to avoid type-checking and use just parsing, which should be enough for stringer. Separately reopening golang/go#10249 because the original change closed that issue, but the change is itself causing other problems as described in the discussion at golang/go#25650. This reversion restores the old behavior of stringer and will be followed with other fixes if they can be worked out. Change-Id: I8404d78da08043ede1a36b0e135a3fc7fdf6728d Reviewed-on: https://go-review.googlesource.com/121884 Reviewed-by: Ian Lance Taylor --- cmd/stringer/endtoend_test.go | 2 +- cmd/stringer/importer18.go | 16 ---------------- cmd/stringer/importer19.go | 16 ---------------- cmd/stringer/stringer.go | 3 ++- 4 files changed, 3 insertions(+), 34 deletions(-) delete mode 100644 cmd/stringer/importer18.go delete mode 100644 cmd/stringer/importer19.go diff --git a/cmd/stringer/endtoend_test.go b/cmd/stringer/endtoend_test.go index 273f29bd..0c79b1ac 100644 --- a/cmd/stringer/endtoend_test.go +++ b/cmd/stringer/endtoend_test.go @@ -33,7 +33,7 @@ func TestEndToEnd(t *testing.T) { defer os.RemoveAll(dir) // Create stringer in temporary directory. stringer := filepath.Join(dir, "stringer.exe") - err = run("go", "build", "-o", stringer) + err = run("go", "build", "-o", stringer, "stringer.go") if err != nil { t.Fatalf("building stringer: %s", err) } diff --git a/cmd/stringer/importer18.go b/cmd/stringer/importer18.go deleted file mode 100644 index fd21873c..00000000 --- a/cmd/stringer/importer18.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !go1.9 - -package main - -import ( - "go/importer" - "go/types" -) - -func defaultImporter() types.Importer { - return importer.Default() -} diff --git a/cmd/stringer/importer19.go b/cmd/stringer/importer19.go deleted file mode 100644 index deddadb1..00000000 --- a/cmd/stringer/importer19.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build go1.9 - -package main - -import ( - "go/importer" - "go/types" -) - -func defaultImporter() types.Importer { - return importer.For("source", nil) -} diff --git a/cmd/stringer/stringer.go b/cmd/stringer/stringer.go index 4b8d1ba4..1d59e9b3 100644 --- a/cmd/stringer/stringer.go +++ b/cmd/stringer/stringer.go @@ -66,6 +66,7 @@ import ( "go/build" exact "go/constant" "go/format" + "go/importer" "go/parser" "go/token" "go/types" @@ -268,7 +269,7 @@ func (g *Generator) parsePackage(directory string, names []string, text interfac // check type-checks the package. The package must be OK to proceed. func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) { pkg.defs = make(map[*ast.Ident]types.Object) - config := types.Config{Importer: defaultImporter(), FakeImportC: true} + config := types.Config{Importer: importer.Default(), FakeImportC: true} info := &types.Info{ Defs: pkg.defs, }