-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Forked from #31561. This issue is not for users of cgo packages; that issue is #35720.
Beta instructions: #35721 (comment) contains instructions on how to build a version of Go and gopls that should work well for authoring cgo packages.
Files that import "C" are not really valid Go. They depend heavily on extra information that is produced by the go tool when it builds the package. They can be parsed, but not type checked, though there is some rudimentary support for working around the issues by setting the go/types.Config.FakeImportC
flag.
Many people have suggested that gopls use the package's GoFiles rather than its CompiledGoFiles. The GoFiles are the original (invalid) files. Using those may give a slightly better experience for people editing the package, but it will completely break anything that depends on the type information, since the package will no longer type check. We would have to evaluate the effects very carefully before making that change in the current architecture.
We could consider type checking cgo packages twice, once with the real code and once with the user's code. That would be a significant architectural change.
Alternatively, we could run the cgo tool as the .go files change to produce the real code. This is a much more robust approach, but the cost of running cgo processing may be too high, especially on large packages.
No matter what, this is a large project that will need a lot of testing and thought. It's unlikely we'll make huge improvements here very soon.