-
Notifications
You must be signed in to change notification settings - Fork 18k
reflect: TypeOf(unsafe.Pointer(nil)).PkgPath() returns "", not "unsafe" #44830
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
@mdempsky, thank you for catching this discrepancy, nice work! If I may ask, perhaps should we repurpose this as a proposal to include unsafe.Pointer into builtin but also to update the spec? I think this was just an oversight from commit 20850fc almost 12 years ago in which we perhaps forgot to update the spec. @robpike @rsc @griesemer @ianlancetaylor is my assumption correct? Thank you. |
unsafe.Pointer is mentioned in the spec. It's also declared in package unsafe, not the universe, so it's properly not listed as a predeclared type/identifier. I don't see any reason to change the spec here. |
At first glance this seems like a compiler bug to me. It's probably treating |
I can believe it's actually a compiler bug. FWIW, it looks like with gccgo 11, both PkgPath and also Name return |
For gccgo it's a libgo bug, because libgo holds the unique type descriptor for |
Sure. I'm just pointing out a similar issue also affects gccgo. |
It looks Go spec views unsafe things as builtin things in several places.
|
Change https://golang.org/cl/313349 mentions this issue: |
Change https://golang.org/cl/313890 mentions this issue: |
This fixes golang/go#44830 for GopherJS.
The documentation for reflect.Type.PkgPath says:
unsafe.Pointer is not listed as a predeclared type: https://golang.org/ref/spec#Predeclared_identifiers (Though go/types lists it as one: https://golang.org/pkg/go/types/#BasicKind)
So it seems to reason that PkgPath should return "unsafe", but it instead returns "": https://play.golang.org/p/ZnUOgHjwz58
/cc @griesemer @ianlancetaylor
The text was updated successfully, but these errors were encountered: