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,internal/goroot: testdata
is surprisingly treated as a standard-library package
#65406
Comments
Looks like this is due to the special name |
@bcmills @matloob I think this behavior may be a bug, or should be documented at https://go.dev/ref/mod, which appears to mention only testdata directories, not module names. It's particularly surprising that e.g. Repurposing this issue to mitigate the surprise. |
Change https://go.dev/cl/559457 mentions this issue: |
supposedly almost all undotted names are considered reserved #37641 ? |
@seankhliao yes, if that were uniformly enforced I think that would be a fine solution. But any other undotted name works in this case -- |
I assigned it to myself for the gopls CL above; reassigning to bcmills for the go command behavior. |
The
@adonovan, can you give more concrete steps to reproduce the behavior seen in the marker tests? |
Hmm. I guess in theory this shouldn't be ambiguous, because the So I think this is arguably a bug in |
testdata
is surprisingly treated as a standard-library package
This session reduces the problem to the two packages.Load calls made by gopls. First we use the name
Now we use
The difference is that the dir/... query in the second case matches the testdata directory in the standard library, making it ambiguous. This causes gopls to issue the second query using file=, which creates the ad hoc package. So this reduces to:
So the question is: is testdata really a standard package? The same behavior occurs when the go.mod name conflicts with any other standard library directory name, such as |
Updates golang/go#65406 Change-Id: I1ce4e4d94f118c4b51dc52d624d90e2f7e05f048 Reviewed-on: https://go-review.googlesource.com/c/tools/+/559457 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@bcmills. Do you think we should change IsStandardImportPath (and the moduleindex variant of it) to check to see that there's at least one .go file in the directory? |
We probably should, yeah. We can probably get rid of the call to |
Change https://go.dev/cl/561338 mentions this issue: |
Usually we're using the module index, so we probably won't hit the goroot.IsStandardPackage function so caching it probably wouldn't make a big difference. |
Oh! I just remembered https://go.dev/cl/504063, which seems very closely related. I wonder if it would be less error-prone for future maintenance to establish the invariant that |
Be more strict in IsStandardPackage: before this change we'd just check for the existence of the directory, but now we check to see that there's at least one .go file in the directory. Also update some comments in the modindex package to reflect the fact that an IndexPackage might represent a directory that does not contain any source files. Fixes golang#65406 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: I82f0c0e7bfcd5bb4df0195c4c8c7fc7c67fae53e Reviewed-on: https://go-review.googlesource.com/c/go/+/561338 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This marker test (of hover) fails spuriously because the name of the package is incorrect:
The actual value is
command-line-arguments/var/folders/fy/dn6v01n16zjdwsqy_8qfbbxr000_9w/T/Testhoverembed.txt4282490610/001/work
, nottestdata
. I think this is a bug in the metadata. Moving p.go to a subdirectory p fixes the problem. Renaming testdata to example.commakes no differenceis an effective workaround.The text was updated successfully, but these errors were encountered: