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: incorrect intermediate test variant computed for broken 'main' import #66126

Open
findleyr opened this issue Mar 6, 2024 · 2 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@findleyr
Copy link
Contributor

findleyr commented Mar 6, 2024

In #66109, we see gopls running into a latent go/packages bug.

Consider the following setup (taken from the gopls regression test for that issue):

-- go.mod --
module example.com/tools

go 1.22

-- tools_test.go --
//go:build tools

package tools

import (
	_ "example.com/tools/tool"
)

-- tool/tool.go --
package main

func main() {
}

In this case, gopackages -test -json -deps ./tools_test.go will report a package "command-line-arguments [command-line-arguments.test]" with the nonsensical dependency ID "example.com/tools/tool [command-line-arguments.test]". This only occurs if the dep is a main package itself. It looks like go/packages thinks it has to break a cycle to the non-existent command-line-arguments package.

CC @adonovan @matloob

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 6, 2024
@gopherbot gopherbot added this to the Unreleased milestone Mar 6, 2024
@gopherbot
Copy link

Change https://go.dev/cl/569035 mentions this issue: gopls/internal/cache: prune broken edges to command-line-arguments pkgs

gopherbot pushed a commit to golang/tools that referenced this issue Mar 6, 2024
Fix two bugs discovered during the investigation of golang/go#66109,
which revealed the strange and broken intermediate test variant form
"path/to/command/package [command-line-arguments.test]", referenced from
the equally broken
"command-line-arguments [command-line-arguments.test]". This latter
package was *also* detected as an ITV, which is why we never tried to
type check it in gopls@v0.14.2.

- Snapshot.orphanedFileDiagnostics was not pruning intermediate test
  variants, causing it to be the one place where we were now type
  checking ITVs.
- Fix the latent bug that caused gopls to record a dangling edge between
  the two ITVs.

There is a third bug in go/packages, filed as golang/go#66126.

Fixes golang/go#66109

Change-Id: Ie5795b6d5a4831bf2f73217c8eb22c6ba18e59cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/569035
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
@gopherbot
Copy link

Change https://go.dev/cl/569437 mentions this issue: [gopls-release-branch.0.15] gopls/internal/cache: prune broken edges to command-line-arguments pkgs

gopherbot pushed a commit to golang/tools that referenced this issue Mar 6, 2024
…to command-line-arguments pkgs

Fix two bugs discovered during the investigation of golang/go#66109,
which revealed the strange and broken intermediate test variant form
"path/to/command/package [command-line-arguments.test]", referenced from
the equally broken
"command-line-arguments [command-line-arguments.test]". This latter
package was *also* detected as an ITV, which is why we never tried to
type check it in gopls@v0.14.2.

- Snapshot.orphanedFileDiagnostics was not pruning intermediate test
  variants, causing it to be the one place where we were now type
  checking ITVs.
- Fix the latent bug that caused gopls to record a dangling edge between
  the two ITVs.

There is a third bug in go/packages, filed as golang/go#66126.

Fixes golang/go#66109

Change-Id: Ie5795b6d5a4831bf2f73217c8eb22c6ba18e59cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/569035
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
(cherry picked from commit caf5940)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/569437
Auto-Submit: Robert Findley <rfindley@google.com>
@mknyszek mknyszek added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants