-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
go/types: handle "C" package differently from gc #12667
Comments
CL https://golang.org/cl/14722 mentions this issue. |
BTW: A file that uses import "C" is not necessarily a well formed Go source file. Aside from the issue of the unreferenced package name, in cgo files, references to unexported package members like C.int are allowed, and calls to functions act as if overloaded to have two variants, one that returns two results, the second being the value of errno. So from the tool designer's perspective, files that import "C" behave like a different language that requires preprocessing to create Go code. Have you tried using the golang.org/x/tools/go/loader package? It takes care of loading a complete Go program from source. It does cgo preprocessing as needed. |
Re: golang.org/x/tools/go/loader I see that it still uses go/types from x/tools repo. I just switched to go/types from std lib, if I use loader I will have to switch back... Are there plans to switch loader (and other packages and tools) to go/types from std lib? And, well, x/tools/go/types does not have this bug fixed. |
Hi Dmitry, sorry I missed your comment till now.
Yes, we plan to switch the loader to use the standard go/types package once Go 1.6 has settled. Before then, we will copy ~every file in the tools repo and tag them go1.5 so that the tip of the tree continues to work with old and new toolchains. This has not yet happened because I have been starved of time for external Go work. |
@dvyukov I will probably start working on this go/tools conversion soon if @alandonovan doesn't have a chance before me. |
Two programs:
The first one is compiled with gc compiler (in fact, it is an excerpt from runtime/cgo/cgo.go), but gotype fails on it saying:
For the second one gc fails with:
but gotype compiles it successfully.
go/types behavior should match gc behavior.
This came up during a real attempt to use go/types to parse packages that use cgo (e.g. net).
The text was updated successfully, but these errors were encountered: