// PackageName returns the package part of the symbol name,
// or the empty string if there is none.
func (s *Sym) PackageName() string {
- pathend := strings.LastIndex(s.Name, "/")
+ name := s.Name
+
+ // A prefix of "type." and "go." is a compiler-generated symbol that doesn't belong to any package.
+ // See variable reservedimports in cmd/compile/internal/gc/subr.go
+ if strings.HasPrefix(name, "go.") || strings.HasPrefix(name, "type.") {
+ return ""
+ }
+
+ pathend := strings.LastIndex(name, "/")
if pathend < 0 {
pathend = 0
}
- if i := strings.Index(s.Name[pathend:], "."); i != -1 {
- return s.Name[:pathend+i]
+ if i := strings.Index(name[pathend:], "."); i != -1 {
+ return name[:pathend+i]
}
return ""
}
assertString(t, fmt.Sprintf("receiver of %q", s1.Name), s1.ReceiverName(), "(*FlagSet)")
assertString(t, fmt.Sprintf("receiver of %q", s2.Name), s2.ReceiverName(), "")
}
+
+func TestIssue29551(t *testing.T) {
+ symNames := []string{
+ "type..eq.[9]debug/elf.intName",
+ "type..hash.debug/elf.ProgHeader",
+ "type..eq.runtime._panic",
+ "type..hash.struct { runtime.gList; runtime.n int32 }",
+ "go.(*struct { sync.Mutex; math/big.table [64]math/big",
+ }
+
+ for _, symName := range symNames {
+ s := Sym{Name: symName}
+ assertString(t, fmt.Sprintf("package of %q", s.Name), s.PackageName(), "")
+ }
+}