mirror of
https://github.com/golang/go
synced 2024-11-21 16:34:42 -07:00
debug/gosym,cmd/compile/internal/ir: use hash to identify duplicate unexported function
This commit is contained in:
parent
707eba9b94
commit
b36aefc95e
@ -13,6 +13,8 @@ import (
|
||||
"fmt"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"hash/fnv"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// An Expr is a Node that can appear as an expression.
|
||||
@ -1183,17 +1185,21 @@ func MethodSymSuffix(recv *types.Type, msym *types.Sym, suffix string) *types.Sy
|
||||
fmt.Fprintf(&b, "%-S", recv)
|
||||
}
|
||||
|
||||
b.WriteString(".")
|
||||
b.WriteString(msym.Name)
|
||||
|
||||
// A particular receiver type may have multiple non-exported
|
||||
// methods with the same name. To disambiguate them, include a
|
||||
// package qualifier for names that came from a different
|
||||
// package than the receiver type.
|
||||
if !types.IsExported(msym.Name) && msym.Pkg != rpkg {
|
||||
b.WriteString(".")
|
||||
b.WriteString(msym.Pkg.Prefix)
|
||||
b.WriteString("+")
|
||||
|
||||
h := fnv.New32()
|
||||
h.Write([]byte(msym.Pkg.Prefix))
|
||||
b.WriteString(strconv.FormatUint(uint64(h.Sum32()), 16))
|
||||
}
|
||||
|
||||
b.WriteString(".")
|
||||
b.WriteString(msym.Name)
|
||||
b.WriteString(suffix)
|
||||
return rpkg.LookupBytes(b.Bytes())
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ func endtest() {
|
||||
// skipIfNotELF skips the test if we are not running on an ELF system.
|
||||
// These tests open and examine the test binary, and use elf.Open to do so.
|
||||
func skipIfNotELF(t *testing.T) {
|
||||
t.Helper()
|
||||
switch runtime.GOOS {
|
||||
case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris", "illumos":
|
||||
// OK.
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func assertString(t *testing.T, dsc, out, tgt string) {
|
||||
t.Helper()
|
||||
if out != tgt {
|
||||
t.Fatalf("Expected: %q Actual: %q for %s", tgt, out, dsc)
|
||||
}
|
||||
@ -85,3 +86,28 @@ func TestIssue29551(t *testing.T) {
|
||||
assertString(t, fmt.Sprintf("package of %q", tc.sym.Name), tc.sym.PackageName(), tc.pkgName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue66313(t *testing.T) {
|
||||
tests := []struct {
|
||||
sym Sym
|
||||
packageName string
|
||||
receiverName string
|
||||
baseName string
|
||||
}{
|
||||
{Sym{Name: "github.com/google/cel-go/parser/gen.(*CELLexer).reset+10c630b8"},
|
||||
"github.com/google/cel-go/parser/gen",
|
||||
"(*CELLexer)",
|
||||
"reset+10c630b8",
|
||||
},
|
||||
{Sym{Name: "ariga.io/atlas/sql/sqlclient.(*Tx).grabConn+404a5a3"},
|
||||
"ariga.io/atlas/sql/sqlclient",
|
||||
"(*Tx)",
|
||||
"grabConn+404a5a3"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
assertString(t, fmt.Sprintf("package of %q", tc.sym.Name), tc.sym.PackageName(), tc.packageName)
|
||||
assertString(t, fmt.Sprintf("receiver of %q", tc.sym.Name), tc.sym.ReceiverName(), tc.receiverName)
|
||||
assertString(t, fmt.Sprintf("package of %q", tc.sym.Name), tc.sym.BaseName(), tc.baseName)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user