-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: go list reports a mangled ImportPath for a relative path that is not a valid Go package #36008
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
Comments
/cc @jayconrod @bcmills |
This is closely related to #33157. We cannot in general assume that an empty directory within a module corresponds to that package import path. For example, if there were a |
Note that the change in behavior from
|
It is admittedly a bit strange that we emit a mangled ImportPath instead of leaving it at the user-provided |
This needs a fix, but the fix that is needed is not to report a module-relative path. I think we should preserve the original argument passed by the user (or That is, the output should be more like:
|
@bcmills for clarification, can you explain why the situation is different if the directory just happens to contain any |
If the directory does contain a |
I see -- so the thinking is that if the directory doesn't contain a Go file, it isn't a valid package, and reporting it as such could be dangerous/misleading since the build tool wouldn't be able to flag the ambiguous import path (or, in another scenario, the build tool could report a conflict based on a directory that doesn't contain Thanks, I believe I understand now. My workflow should be unblocked with Go 1.14, since at that point the overall operation of listing the packages will not fail, and I can filter out non-packages based on the error state being set in the JSON. |
Hi, i would like to work on that issue. |
Change https://golang.org/cl/212358 mentions this issue: |
I'd argue against changing It's fine of course to report the original name by which a package was loaded (command line argument or import string) in error messages. I think we're already doing that though in
|
Yes, we definitely should not return inconsistent gopls will try to do the best it can loading the packages, and it uses the import path fields as part of building the package graph. |
Note that the issue as originally reported is in module mode, not The mangled path is only correct in
|
To put it another way: there is no “correct”
That leaves only one viable option for the import path: whatever path the user requested, even if it is malformed. (Or, I suppose, we could leave the |
This appears to be fixed by CL 185345:
|
Change https://golang.org/cl/185345 mentions this issue: |
What version of Go are you using (
go version
)?Using
gotip
as of 12/5/2019 because this workflow fails with an error using Go 1.13.4:What did you do?
What did you expect to see?
What did you see instead?
When running with Go 1.13.4, see:
This is likely #35414, which has been fixed on tip.
Further information/context
When a Go file is added to the directory, the output is as expected:
The behavior previously worked as I would expect in GOPATH mode:
If the
list
command can find thego.mod
file and determine the import path relative to that, it would be helpful if it returned the import path if Go files existed in the directory rather than the_
import path.The text was updated successfully, but these errors were encountered: