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

x/tools/go/packages: go list emits no CompiledGoFiles for packages that depend on one with an error #28755

Open
alandonovan opened this issue Nov 13, 2018 · 0 comments

Comments

Projects
None yet
4 participants
@alandonovan
Copy link
Contributor

commented Nov 13, 2018

The TestLoadSyntaxError test case establishes an import graph a->b->c->d->e->f where e contains an error:

$ head $(find src -name \*.go)
==> src/golang.org/fake/d/d.go <==
package d; import "golang.org/fake/e"; const D = "d" + e.E
==> src/golang.org/fake/c/c.go <==
package c; import "golang.org/fake/d"; const C = "c" + d.D
==> src/golang.org/fake/f/f.go <==
package f; const F = "f"
==> src/golang.org/fake/e/e.go <==
package e; import "golang.org/fake/f"; const E = "e" + f.F + 1
==> src/golang.org/fake/b/b.go <==
package b; import "golang.org/fake/c"; const B = "b" + c.C
==> src/golang.org/fake/a/a.go <==
package a; import "golang.org/fake/b"; const A = "a" + b.B

If you run tip go list on a and c (as in the test), the reported set of CompiledGoFiles is accurate only for e and f, but not for any package above them, presumably because no build was attempted for those packages:

$ go list -compiled -f '{{.ImportPath}} {{.GoFiles}} {{.CompiledGoFiles}}' -deps -export golang.org/fake/a golang.org/fake/c 
# golang.org/fake/e
src/golang.org/fake/e/e.go:1:60: cannot convert "ef" (type untyped string) to type int
src/golang.org/fake/e/e.go:1:60: invalid operation: "ef" + 1 (mismatched types string and int)
golang.org/fake/f [f.go] [f.go]
golang.org/fake/e [e.go] [e.go]
golang.org/fake/d [d.go] []
golang.org/fake/c [c.go] []
golang.org/fake/b [b.go] []
golang.org/fake/a [a.go] []

Eliminating the type error cause go list to report CompiledGoFiles all the way up:

$ GOPATH=$(pwd) go list -compiled -f '{{.ImportPath}} {{.GoFiles}} {{.CompiledGoFiles}}' -deps -export golang.org/fake/a golang.org/fake/c 
golang.org/fake/f [f.go] [f.go]
golang.org/fake/e [e.go] [e.go]
golang.org/fake/d [d.go] [d.go]
golang.org/fake/c [c.go] [c.go]
golang.org/fake/b [b.go] [b.go]
golang.org/fake/a [a.go] [a.go]

This is arguably a bug in go list, but it suggests we need better test coverage and a more complex and better documented workaround for missing CompiledGoFiles than go/packages has today.

@gopherbot gopherbot added this to the Unreleased milestone Nov 13, 2018

@alandonovan alandonovan changed the title x/tools/go/packages: subtle bugs related to CompiledGoFiles x/tools/go/packages: go list emits no CompiledGoFiles for packages that depend on one with an error Nov 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.