Skip to content

reflect: TypeOf(unsafe.Pointer(nil)).PkgPath() returns "", not "unsafe" #44830

@mdempsky

Description

@mdempsky

The documentation for reflect.Type.PkgPath says:

    // PkgPath returns a defined type's package path, that is, the import path
    // that uniquely identifies the package, such as "encoding/base64".
    // If the type was predeclared (string, error) or not defined (*T, struct{},
    // []int, or A where A is an alias for a non-defined type), the package path
    // will be the empty string.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions