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
go/types: uses $GOROOT/pkg/$GOOS_$GOARCH/unsafe.a incorrectly #22112
Comments
@rsc which package did you use to import the data into go/types? I believe that's who's responsible for ensuring that unsafe is always the same. (Not 100% sure about that but I've been poking around in various importers the last few days and noticed code like "if importing unsafe then return types.Unsafe") |
Reproduction:
It fails quite loudly. The first few lines of output are:
and so on. |
go/types just uses whatever importer is provided. In this case, it's going to be the default importer which is the gc importer. Since the It's certainly easy to not call any importer at all for "unsafe". |
Change https://golang.org/cl/67634 mentions this issue: |
The Go vendor spec explicitly says that
It sounds like a bug in gc or 'go build' to me, not go/types. |
ping @rsc |
Sigh. Obviously my memory is going. OK. Well, the importer is going to get rewritten as part of package management and workspace abstraction issues, so that will probably fix this anyway. So I guess nothing to do now. |
FWIW, it doesn't make a lot of sense to me to vendor package unsafe - I'd be fine to disallow this and perhaps even state it in the spec that importing unsafe means only one thing and cannot be changed. |
The Go compiler treats import "unsafe" as special - even if there is a vendor/unsafe directory, or a compiled unsafe.a package file, it doesn't use any of those - import "unsafe" always means the real unsafe, no matter what.
go/types appears not to follow this rule. I accidentally created a $GOROOT/pkg/darwin_amd64/unsafe.a, and that causes go/types to fail to typecheck just about any code using unsafe, because it no longer uses the real unsafe.
Obviously I will fix my problem and stop generating unsafe.a, but go/types should still refuse to treat import "unsafe" as anything other than the real unsafe.
/cc @adonovan @griesemer
The text was updated successfully, but these errors were encountered: