-
Notifications
You must be signed in to change notification settings - Fork 18k
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/ssa/ssautil: clarify that LoadAllSyntax is required, and provide better errors #28106
Comments
The doc comment for ssautil.Packages says "a set of packages loaded from source syntax". This is admittedly not very clear, but it means you need to use Both the documentation and the way in which the error is reported could certainly be improved. |
You're right; I should have noticed that. I agree that the docs could be a bit clearer, and that it would be great if I got confused by how this succeeded on 1.11, and failed on 1.10 under some circumstances. I guess I was getting lucky somehow. |
Hmm, on closer inspection the API does intend to support exactly what you're doing, with a mixture of packages loaded from source and from export data, and there's even an Example of it. Using AllSyntax will likely be an effective workaround, but the bug as originally reported is real. |
Change https://golang.org/cl/141686 mentions this issue: |
The root cause is that go/packages' go1.10 "fallback" loads the entire program from source because go1.10 list doesn't generate export data; however, it doesn't bother to type-check function bodies of imports in this mode since the function types are all that it needs. However, the SSA builder assumes that when a package has syntax trees, they have been type checked, and consequently it panics when it finds function bodies without type information. https://go-review.googlesource.com/c/tools/+/141686 contains a fix. |
Does this mean that it's entirely reasonable for me to use |
Yes. |
I encountered this weird issue while converting https://github.com/mvdan/unparam to
go/packages
. You can see the CI status here, where 1.11.1 is green, yet 1.10.4 is red: https://travis-ci.org/mvdan/unparam/builds/439236099I've boiled it down to this piece of code: https://play.golang.org/p/vUTgArM21wJ
To reproduce, run:
Locally, on
go version devel +165ebaf97b Sun Oct 7 02:36:02 2018 +0000 linux/amd64
, the commands above succeed.Here is the behavior with 1.10.4 - I'm using a Docker image to ensure that it's easy to reproduce for everyone. Funnily enough, I could not reproduce it on my Linux system with a binary installation of 1.10.4.
The original panic was different; I'm pasting the start of it below. However, since both only happen on 1.10 and this is the minimised case of the original panic, I'm pretty sure they are the same bug.
Since it only happens on 1.10, this might be a bug in a package in the standard library like
go/types
. I haven't investigated further.Unfortunately, this does make using
go/packages
in my tool quite painful. I'd rather not drop support for Go 1.10 just yet./cc @ianthehat @alandonovan
The text was updated successfully, but these errors were encountered: