Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.11.5 #174

Merged
merged 8 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-10.15, macos-11]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

Expand Down
3 changes: 3 additions & 0 deletions internal/go/printer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,9 @@ func declToken(decl ast.Decl) (tok token.Token) {
func (p *printer) declList(list []ast.Decl) {
tok := token.ILLEGAL
for _, d := range list {
if gd, ok := d.(*ast.GenDecl); ok && len(gd.Specs) == 0 {
continue // skip empty genDecl
}
prev := tok
tok = declToken(d)
// If the declaration token changed (e.g., from CONST to TYPE)
Expand Down
3 changes: 0 additions & 3 deletions package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,6 @@ func TestDeleteType(t *testing.T) {
t.Fatal("TypeDecl.State failed")
}
domTest(t, pkg, `package main


`)
}

Expand Down Expand Up @@ -1333,7 +1331,6 @@ var (
y string
)
var x string = "Hello, " + "Go+"

`)
}

Expand Down
20 changes: 18 additions & 2 deletions packages/imp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Importer struct {
dir string
}

// NewImporter creates an Importer object that meets types.Importer interface.
func NewImporter(fset *token.FileSet, workDir ...string) *Importer {
dir := ""
if len(workDir) > 0 {
Expand All @@ -34,10 +35,23 @@ func NewImporter(fset *token.FileSet, workDir ...string) *Importer {
}

func (p *Importer) Import(pkgPath string) (pkg *types.Package, err error) {
return p.ImportFrom(pkgPath, p.dir, 0)
}

// ImportFrom returns the imported package for the given import
// path when imported by a package file located in dir.
// If the import failed, besides returning an error, ImportFrom
// is encouraged to cache and return a package anyway, if one
// was created. This will reduce package inconsistencies and
// follow-on type checker errors due to the missing package.
// The mode value must be 0; it is reserved for future use.
// Two calls to ImportFrom with the same path and dir must
// return the same package.
func (p *Importer) ImportFrom(pkgPath, dir string, mode types.ImportMode) (*types.Package, error) {
if ret, ok := p.loaded[pkgPath]; ok && ret.Complete() {
return ret, nil
}
expfile := findExport(p.dir, pkgPath)
expfile := FindExport(dir, pkgPath)
if expfile == "" {
return nil, syscall.ENOENT
}
Expand All @@ -64,7 +78,9 @@ type listExport struct {
Export string `json:"Export"`
}

func findExport(dir, pkgPath string) (expfile string) {
// FindExport lookups export file (.a) of a package by its pkgPath.
// It returns empty if pkgPath not found.
func FindExport(dir, pkgPath string) (expfile string) {
var ret listExport
if data, err := golistExport(dir, pkgPath); err == nil {
json.Unmarshal(data, &ret)
Expand Down
2 changes: 1 addition & 1 deletion packages/imp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Test_loadByExport(t *testing.T) {
if _, err := p.loadByExport("/not-found", "notfound"); !os.IsNotExist(err) {
t.Fatal("Test_loadByExport: no error?")
}
findExport(".", "C")
FindExport(".", "C")
}

// ----------------------------------------------------------------------------