-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/go: SWIG causes generated C++ sources in CompiledGoFiles #37098
Comments
/cc @matloob |
This looks like a valid problem. I wonder why this is happening? The SwigCXXFiles should be put in other sources along with the rest of the non-go source files. |
Hi, @noahgoldman, would you like to contribute your repro case to packages_test with a t.Skip()? That will make it a bit easier for us to take the next steps on getting to a fix. Thanks! |
Change https://golang.org/cl/228637 mentions this issue: |
@matloob I've created a review for this (see comment above). Please let me know if this looks correct! |
Thanks! |
When SWIG is used in a package, the returned "(*package.Package)" from "packages.Load" contains C++ sources in "CompiledGoFiles". This adds a skipped failing test case that reproduces this issue. Updates golang/go#37098. Change-Id: I56a875c6ad9d18508413b00c34d6b6ac0b116fda Reviewed-on: https://go-review.googlesource.com/c/tools/+/228637 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
* internal/lsp/source: add extra nil check in searchForEnclosing df70183b * internal/lsp: fix logged message for gc_details e8769ccb * internal/lsp: remove uses of crypto/sha1 in gopls 0dd562f3 * internal/lsp: show compiler optimization decisions 95780ea8 * internal/lsp: de-duplicate logic for canExtractVariable edd3c8e9 * internal/lsp: check URIs of all workspace folders 342ee105 * internal/lsp/source: add a unit test for searchForEnclosing e7a7e3a8 * internal/lsp: remove PackageHandle b6476686 * internal/lsp: replace ParseGoHandle with concrete data a9439ae9 * internal/lsp/cache: fix parseKey 4d1d9acc * internal/lsp: pass snapshot/view to memoize.Functions 72051f79 * internal/lsp/cache: remove files from the memoize.Store 60da08ac * internal/lsp: minimize PackageHandle interface 051e64e6 * internal/lsp: handle bad formatting with CRLF line endings 2ad651e9 * internal/lsp: support return statements in extract function 3c048e20 * internal/lsp: update code for LSP protocol cd83430b * internal/lsp: allow narrower scope for convenience CodeActions 55644ead * internal/lsp: correctly marshal arguments for upgrade code lens 7b4c4ad3 * internal/lsp: correctly invalidate metadata for batched changes 59c6fc0b * internal/lsp: support refactor.extract through commands 92670837 * internal/lsp: fix hover link for embedded fields and methods eaaaedc6 * internal/lsp: fix GlobPattern for watching files 102e7d35 * internal/lsp: add parse errors as diagnostics even when parsing fails b5fc9d35 * internal/lsp: fix hover for implicit type switch variable declarations 7017fd6b * internal/lsp: add errors for missing modules that don't map to an import cbb3c69a * internal/lsp: move undeclaredname suggested fix out of analysis 37a045f3 * internal/lsp/regtest: fix WithoutWorkspaceFolders option 0e1f6f5c * internal/lsp/regtest: add a simple stress test 93b64502 * internal/lsp/regtest: add run options to support stress testing 84d0e3d1 * internal/lsp/fake: move to a struct for configuring the sandbox a5e28d8d * internal/lsp: lift env out of the sandbox into the editor 1ff154e6 * internal/lsp: show errors in indirect dependencies as diagnostics d2c1b4b2 * internal/lsp: treat the module root as the workspace root, if available 0cdb17d1 * internal/lsp/cache: copy *packages.Config environment completely b3d141dd * internal/lsp: don't publish duplicate diagnostics in one report 80cb7970 * go/packages: add failing test for golang/go#37098 188b3828 * go/packages: find filenames in error strings if not in position a7c6fd06 * internal/lsp: separate test and benchmark codelens bd1e9de8 * go/analysis/passes/unmarshal: Add check for asn1.Unmarshal 70419130 * internal/lsp: support `go mod tidy` on save without diagnostics 6123e778 * internal/lsp: try to parse diagnostics out of `go list` errors b42efcd1 * internal/lsp: handle unknown revision in go.mod file 0a5cd101 * internal/lsp: handle on-disk file deletions for opened files acdb8c15 * internal/lsp: change the way that we pass arguments to command 5ea36318 * internal/lsp: return the actual range from convenience code actions b8e13e1a
* gopls/integration/govim: enable running at main 1c30660f * internal/lsp: fix a few staticcheck suggestions, some cleanup 6b78e25f * internal/lsp: don't show diagnostic in go.mod for direct dependencies 8afe7e08 * internal/lsp: properly check for nil on i.enclosing 449c5851 * internal/lsp/source: move initial extract function logic to lsp/command 1c1ec420 * internal/lsp/source: add extra nil check in searchForEnclosing df70183b * internal/lsp: fix logged message for gc_details e8769ccb * internal/lsp: remove uses of crypto/sha1 in gopls 0dd562f3 * internal/lsp: show compiler optimization decisions 95780ea8 * internal/lsp: de-duplicate logic for canExtractVariable edd3c8e9 * internal/lsp: check URIs of all workspace folders 342ee105 * internal/lsp/source: add a unit test for searchForEnclosing e7a7e3a8 * internal/lsp: remove PackageHandle b6476686 * internal/lsp: replace ParseGoHandle with concrete data a9439ae9 * internal/lsp/cache: fix parseKey 4d1d9acc * internal/lsp: pass snapshot/view to memoize.Functions 72051f79 * internal/lsp/cache: remove files from the memoize.Store 60da08ac * internal/lsp: minimize PackageHandle interface 051e64e6 * internal/lsp: handle bad formatting with CRLF line endings 2ad651e9 * internal/lsp: support return statements in extract function 3c048e20 * internal/lsp: update code for LSP protocol cd83430b * internal/lsp: allow narrower scope for convenience CodeActions 55644ead * internal/lsp: correctly marshal arguments for upgrade code lens 7b4c4ad3 * internal/lsp: correctly invalidate metadata for batched changes 59c6fc0b * internal/lsp: support refactor.extract through commands 92670837 * internal/lsp: fix hover link for embedded fields and methods eaaaedc6 * internal/lsp: fix GlobPattern for watching files 102e7d35 * internal/lsp: add parse errors as diagnostics even when parsing fails b5fc9d35 * internal/lsp: fix hover for implicit type switch variable declarations 7017fd6b * internal/lsp: add errors for missing modules that don't map to an import cbb3c69a * internal/lsp: move undeclaredname suggested fix out of analysis 37a045f3 * internal/lsp/regtest: fix WithoutWorkspaceFolders option 0e1f6f5c * internal/lsp/regtest: add a simple stress test 93b64502 * internal/lsp/regtest: add run options to support stress testing 84d0e3d1 * internal/lsp/fake: move to a struct for configuring the sandbox a5e28d8d * internal/lsp: lift env out of the sandbox into the editor 1ff154e6 * internal/lsp: show errors in indirect dependencies as diagnostics d2c1b4b2 * internal/lsp: treat the module root as the workspace root, if available 0cdb17d1 * internal/lsp/cache: copy *packages.Config environment completely b3d141dd * internal/lsp: don't publish duplicate diagnostics in one report 80cb7970 * go/packages: add failing test for golang/go#37098 188b3828 * go/packages: find filenames in error strings if not in position a7c6fd06 * internal/lsp: separate test and benchmark codelens bd1e9de8 * go/analysis/passes/unmarshal: Add check for asn1.Unmarshal 70419130 * internal/lsp: support `go mod tidy` on save without diagnostics 6123e778 * internal/lsp: try to parse diagnostics out of `go list` errors b42efcd1 * internal/lsp: handle unknown revision in go.mod file 0a5cd101 * internal/lsp: handle on-disk file deletions for opened files acdb8c15 * internal/lsp: change the way that we pass arguments to command 5ea36318 * internal/lsp: return the actual range from convenience code actions b8e13e1a
* gopls/integration/govim: enable running at main 1c30660f * internal/lsp: fix a few staticcheck suggestions, some cleanup 6b78e25f * internal/lsp: don't show diagnostic in go.mod for direct dependencies 8afe7e08 * internal/lsp: properly check for nil on i.enclosing 449c5851 * internal/lsp/source: move initial extract function logic to lsp/command 1c1ec420 * internal/lsp/source: add extra nil check in searchForEnclosing df70183b * internal/lsp: fix logged message for gc_details e8769ccb * internal/lsp: remove uses of crypto/sha1 in gopls 0dd562f3 * internal/lsp: show compiler optimization decisions 95780ea8 * internal/lsp: de-duplicate logic for canExtractVariable edd3c8e9 * internal/lsp: check URIs of all workspace folders 342ee105 * internal/lsp/source: add a unit test for searchForEnclosing e7a7e3a8 * internal/lsp: remove PackageHandle b6476686 * internal/lsp: replace ParseGoHandle with concrete data a9439ae9 * internal/lsp/cache: fix parseKey 4d1d9acc * internal/lsp: pass snapshot/view to memoize.Functions 72051f79 * internal/lsp/cache: remove files from the memoize.Store 60da08ac * internal/lsp: minimize PackageHandle interface 051e64e6 * internal/lsp: handle bad formatting with CRLF line endings 2ad651e9 * internal/lsp: support return statements in extract function 3c048e20 * internal/lsp: update code for LSP protocol cd83430b * internal/lsp: allow narrower scope for convenience CodeActions 55644ead * internal/lsp: correctly marshal arguments for upgrade code lens 7b4c4ad3 * internal/lsp: correctly invalidate metadata for batched changes 59c6fc0b * internal/lsp: support refactor.extract through commands 92670837 * internal/lsp: fix hover link for embedded fields and methods eaaaedc6 * internal/lsp: fix GlobPattern for watching files 102e7d35 * internal/lsp: add parse errors as diagnostics even when parsing fails b5fc9d35 * internal/lsp: fix hover for implicit type switch variable declarations 7017fd6b * internal/lsp: add errors for missing modules that don't map to an import cbb3c69a * internal/lsp: move undeclaredname suggested fix out of analysis 37a045f3 * internal/lsp/regtest: fix WithoutWorkspaceFolders option 0e1f6f5c * internal/lsp/regtest: add a simple stress test 93b64502 * internal/lsp/regtest: add run options to support stress testing 84d0e3d1 * internal/lsp/fake: move to a struct for configuring the sandbox a5e28d8d * internal/lsp: lift env out of the sandbox into the editor 1ff154e6 * internal/lsp: show errors in indirect dependencies as diagnostics d2c1b4b2 * internal/lsp: treat the module root as the workspace root, if available 0cdb17d1 * internal/lsp/cache: copy *packages.Config environment completely b3d141dd * internal/lsp: don't publish duplicate diagnostics in one report 80cb7970 * go/packages: add failing test for golang/go#37098 188b3828 * go/packages: find filenames in error strings if not in position a7c6fd06 * internal/lsp: separate test and benchmark codelens bd1e9de8 * go/analysis/passes/unmarshal: Add check for asn1.Unmarshal 70419130 * internal/lsp: support `go mod tidy` on save without diagnostics 6123e778 * internal/lsp: try to parse diagnostics out of `go list` errors b42efcd1 * internal/lsp: handle unknown revision in go.mod file 0a5cd101 * internal/lsp: handle on-disk file deletions for opened files acdb8c15 * internal/lsp: change the way that we pass arguments to command 5ea36318 * internal/lsp: return the actual range from convenience code actions b8e13e1a
@bcmills @jayconrod @matloob: Is there a chance of this getting investigated for 1.16? This is the root cause of a I was able to reproduce using the trivial example from the test in the CL above:
Out of these, the last one ( |
Change https://golang.org/cl/313131 mentions this issue: |
Change https://golang.org/cl/313532 mentions this issue: |
Change https://golang.org/cl/313591 mentions this issue: |
For golang/go#37098 Change-Id: I6edf1b4efca38fe9837ed944bc45c05c37099b4a Reviewed-on: https://go-review.googlesource.com/c/tools/+/313591 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
Now that this issue has been resolved, we can unskip the tests for it. Change-Id: I610122a424bedd2cbd066ea9985239fc319e58ae Reviewed-on: https://go-review.googlesource.com/c/tools/+/313532 Trust: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
* gopls/internal/regtest: unskip tests for golang/go#37098 aec13729 * internal/lsp: don't call PackagesForFile on builtin.go 28c1392e * go/packages: enable TestIssue37098 for Go 1.17 and later 800adbe2 * internal/lsp: print comments that would be lost during extract func 16b25d25 * go/analysis/passes/fieldalignment: clarify reported diagnostics in docs 7c72a848 * internal/lsp: add support for extracting non-nested returns 9ff86487 * internal/lsp/source/completion: suggest only valid package names d0768c91 * internal/lsp/debug: splice in updated servers rather than overwrite 6397a116 * internal/lsp/cmd: add a command-line command to start daemon debugging 7b9993c5 * gopls/test: it is safe to ignore json unmarshalling errors fe1c5480 * gopls: tidy module 735ed62f * cmd/guru: update referrers-json testdata to reflect new line numbering e3dc99f8 * cmd/guru: remove test assertions involving unsafe to fix the build 3f1e7240 * internal/lsp/cache: improve snapshot clone perfomance cf354b66 * gopls/doc: fix broken link 7657be6e * internal/lsp: add a command to start the debug server 7c93484b * lsp/completion: fix postfix completions preceding assignments 716a04c6 * internal/lsp/cache: preallocate internal maps when cloning snapshots f74a6698 * internal/lsp: introduce MemoryMode e435455a * internal/lsp: support Check For Upgrades in vendor mode f7e8e244 * internal/lsp: move gopls/internal/regtest -> internal/lsp/regtest a8e7c0c9
* gopls/internal/regtest: unskip tests for golang/go#37098 aec13729 * internal/lsp: don't call PackagesForFile on builtin.go 28c1392e * go/packages: enable TestIssue37098 for Go 1.17 and later 800adbe2 * internal/lsp: print comments that would be lost during extract func 16b25d25 * go/analysis/passes/fieldalignment: clarify reported diagnostics in docs 7c72a848 * internal/lsp: add support for extracting non-nested returns 9ff86487 * internal/lsp/source/completion: suggest only valid package names d0768c91 * internal/lsp/debug: splice in updated servers rather than overwrite 6397a116 * internal/lsp/cmd: add a command-line command to start daemon debugging 7b9993c5 * gopls/test: it is safe to ignore json unmarshalling errors fe1c5480 * gopls: tidy module 735ed62f * cmd/guru: update referrers-json testdata to reflect new line numbering e3dc99f8 * cmd/guru: remove test assertions involving unsafe to fix the build 3f1e7240 * internal/lsp/cache: improve snapshot clone perfomance cf354b66 * gopls/doc: fix broken link 7657be6e * internal/lsp: add a command to start the debug server 7c93484b * lsp/completion: fix postfix completions preceding assignments 716a04c6 * internal/lsp/cache: preallocate internal maps when cloning snapshots f74a6698 * internal/lsp: introduce MemoryMode e435455a * internal/lsp: support Check For Upgrades in vendor mode f7e8e244 * internal/lsp: move gopls/internal/regtest -> internal/lsp/regtest a8e7c0c9
Change https://golang.org/cl/316770 mentions this issue: |
Change https://golang.org/cl/316771 mentions this issue: |
…h.0.6 42984c4 internal/lsp/regtest: run one quick fix at a time in TestUnknownRevision 19b1717 go.mod: upgrade to Go 1.17 a1fbb68 all: upgrade go.mod files to Go 1.16 062bf4e internal/lsp: make ShowDocument RPC available to gopls 3e17c62 internal/lsp: warn users who have built gopls with go-diff v1.2.0 def0263 gopls: clarify policy with respect to support for older Go versions 7a6108e internal/lsp: don't use ast.NewPackage to build builtin edbe9be internal/lsp/completion: indicate completion candidates that are deprecated 9b9633e internal/lsp/regtest: force GOPACKAGESDRIVER=off 291330a gopls/internal/regtest/modfile: set an explicit go version in the TestUnknownRevision modules aec1372 gopls/internal/regtest: unskip tests for golang/go#37098 28c1392 internal/lsp: don't call PackagesForFile on builtin.go 800adbe go/packages: enable TestIssue37098 for Go 1.17 and later 16b25d2 internal/lsp: print comments that would be lost during extract func 7c72a84 go/analysis/passes/fieldalignment: clarify reported diagnostics in docs 9ff8648 internal/lsp: add support for extracting non-nested returns d0768c9 internal/lsp/source/completion: suggest only valid package names 6397a11 internal/lsp/debug: splice in updated servers rather than overwrite 7b9993c internal/lsp/cmd: add a command-line command to start daemon debugging fe1c548 gopls/test: it is safe to ignore json unmarshalling errors 735ed62 gopls: tidy module e3dc99f cmd/guru: update referrers-json testdata to reflect new line numbering 3f1e724 cmd/guru: remove test assertions involving unsafe to fix the build cf354b6 internal/lsp/cache: improve snapshot clone perfomance 7657be6 gopls/doc: fix broken link 7c93484 internal/lsp: add a command to start the debug server 716a04c lsp/completion: fix postfix completions preceding assignments f74a6698 internal/lsp/cache: preallocate internal maps when cloning snapshots e435455 internal/lsp: introduce MemoryMode f7e8e24 internal/lsp: support Check For Upgrades in vendor mode a8e7c0c internal/lsp: move gopls/internal/regtest -> internal/lsp/regtest f946a15 passes/sigchanyzer: allow valid inlined unbuffered signal channel 4934781 lsp/completion: offer candidates converting arrays to slices b3e5b99 internal/lsp: update unsafe completion test for upcoming spec changes e74674a internal/lsp/protocol: latest version of LSP dbc8747 internal/lsp/semantic: avoid doing semantic tokens for large files a13dbf1 lsp/completion: omit deep completions into unimported package names 10909d8 internal/lsp/cache: remove type info trimming 1dce19d internal/lsp/cache: don't trim types.Info with staticcheck enabled 07295ca internal/lsp/cache: prune types.Info entries in slice literals 1a0c608 internal/lsp/protocol/typescript: update documentation and generated code fe50371 internal/lsp/source: fix Deref function for cyclic types cb5dc85 internal/lsp/cache: add a scheme for types error code links 799b682 gopls/internal/hooks: respect the default checks of the staticcheck tool d1362d7 internal/lsp/source: fix an infinite loop in Deref function 59a2b45 internal/lsp/source: update process of hover signature creation for type declarations 2140cce fix the argument of the goimports example ec686a2 all: upgrade all dependencies except for go-diff 0243799 gopls/internal/coverage: apply gofmt to the build tag syntax be791d0 internal/lsp/source: small fixes to directory filters Change-Id: If0eb9499020d2baab77f05523197adb95044705f
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The function
(golang.org/x/tools/go/packages).Load
was called on a package that uses Swig to generate C++ interfaces. The minimal case to reproduce this behavior is to create a Go source with nothing but a package declarationpackage x
, as well as an empty Swig interface file with the extension.swigcxx
.I can reproduce this with the following test case (utilizing the packagestest package).
What did you expect to see?
I'd expect that that
(golang.org/x/tools/go/packages).Load
would return*Package
types, for which each value ofCompiledGoFiles
would be a Go source file, not a C++ source.The discussion in #28749 and the subsequent change to
golang.org/x/tools/go/packages
indicates that the intention is to only contain Go sources in(*Package).CompiledGoFiles
. The current behavior of removing sources present in(*Package).OtherFiles
from(*Package).CompiledGoFiles
(see golist.go#L546) will filter out any files defined in most of the other fields returned fromgo list ...
(see golist.go#L400).What did you see instead?
The output of
(golang.org/x/tools/go/packages).Load
on a package that uses Swig to generate C++ interfaces results in the package containing Swig-generated C++ in(*Package).CompiledGoFiles
.Here are the results of running the test case above. The test case prints the first 1000 characters of the non-Go sources to show that they are C++ files.
The text was updated successfully, but these errors were encountered: