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
reflect: Type.PkgPath() doesn't return proper import path for vendored import #12739
Comments
I think the value returned by PkgPath is reasonable because Just returning "github.com/ugorji/go/codec" doesn't always Consider this project file layout: Both prjA/pkg1 and vendor/prjB/pkg2 will use their own version of The example might be contrived, but it illustrates the subtlety of Because this kind of vendoring is explicitly supported by the go |
@minux Based on the documentation, the PkgPath is the import path. Documentation states: // PkgPath returns a named type's package path, that is, the import path The vendor implementation should be transparent/invisible at runtime. |
I don't think it's possible for the vendoring experiment to be
transparent.
Do you think one vendored package should be allowed to
modify the unexported fields of another vendored copy of
the same package?
After introducing the vendoring experiment, the import path
can no long uniquely identify a package.
|
This is working as intended. Quoting golang.org/s/go15vendor:
When you ask about the package in question you find out is not the real one but a vendored copy. This is true, and it is correct behavior. |
I had the same question, and this issue answered it. |
This is needed when this package is vendored via Go 1.6 /vendor/ support. The PkgPath returned value does not strip /vendor/ prefix, as documented in golang/go#12739.
"import" statements cannot contain vendor paths when GO15VENDOREXPERIMENT is enabled. golang/go#12111 reflect.PkgPath returns the actual package path used by a type. This can include the vendor directory. golang/go#12739 When writing "import" statements using reflect.PkgPath, /vendor/ should be stripped from the import path.
If the package that easyjson is being used on is vendor'd then we need to strip off the vendor'd bit of the pkg path Fixes: mailru#29 See: golang/go#12739
Hi,
We were using reflect package to get the import path of some of our dependencies. We are using
GO15VENDOREXPERIMENT.
When we call PkgPath() on a Type interface acquired from an instance of a struct from the codec package (
github.com/ugorji/go/codec
) we get import path :bitbucket.org/{our_project_dir}/vendor/github.com/ugorji/go/codec
This is not in line with the PkgPath() call documentation, and we are using those import paths to generate a import clause for our generated go code.
The result looks like this :
This file clearly doesn't compile. Could you please fix the behaviour of the PkgPath() call when the project is using GO15VENDOREXPERIMENT?
The text was updated successfully, but these errors were encountered: