Skip to content

Commit

Permalink
loader: don't return empty packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikh committed Dec 1, 2019
1 parent 99f6b7d commit 82a1013
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion loader/loader.go
Expand Up @@ -30,7 +30,20 @@ func Graph(cfg packages.Config, patterns ...string) ([]*packages.Package, error)
packages.Visit(pkgs, nil, func(pkg *packages.Package) {
pkg.Fset = fset
})
return pkgs, nil

n := 0
for _, pkg := range pkgs {
if len(pkg.CompiledGoFiles) == 0 && pkg.PkgPath != "unsafe" {
// If a package consists only of test files, then
// go/packages incorrectly(?) returns an empty package for
// the non-test variant. Get rid of those packages. See
// #646.
continue
}
pkgs[n] = pkg
n++
}
return pkgs[:n], nil
}

// LoadFromExport loads a package from export data. All of its
Expand Down

0 comments on commit 82a1013

Please sign in to comment.