mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: fix reflect naming of local generic types
To disambiguate local types, we append a "·N" suffix to their name and then trim it off again when producing their runtime type descriptors. However, if a local type is generic, then we were further appending the type arguments after this suffix, and the code in types/fmt.go responsible for trimming didn't know to handle this. We could extend the types/fmt.go code to look for the "·N" suffix elsewhere in the type name, but this is risky because it could legitimately (albeit unlikely) appear in struct field tags. Instead, the most robust solution is to just change the mangling logic to keep the "·N" suffix at the end, where types/fmt.go can easily and reliably trim it. Note: the "·N" suffix is still visible within the type arguments list (e.g., the "·3" suffixes in nested.out), because we currently use the link strings in the type arguments list. Fixes #54456. Change-Id: Ie9beaf7e5330982f539bff57b8d48868a3674a37 Reviewed-on: https://go-review.googlesource.com/c/go/+/424901 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
72a76ca1f9
commit
aa6a7fa775
6 changed files with 72 additions and 14 deletions
|
|
@ -777,8 +777,13 @@ func (dict *readerDict) mangle(sym *types.Sym) *types.Sym {
|
|||
return sym
|
||||
}
|
||||
|
||||
// If sym is a locally defined generic type, we need the suffix to
|
||||
// stay at the end after mangling so that types/fmt.go can strip it
|
||||
// out again when writing the type's runtime descriptor (#54456).
|
||||
base, suffix := types.SplitVargenSuffix(sym.Name)
|
||||
|
||||
var buf strings.Builder
|
||||
buf.WriteString(sym.Name)
|
||||
buf.WriteString(base)
|
||||
buf.WriteByte('[')
|
||||
for i, targ := range dict.targs {
|
||||
if i > 0 {
|
||||
|
|
@ -791,6 +796,7 @@ func (dict *readerDict) mangle(sym *types.Sym) *types.Sym {
|
|||
buf.WriteString(targ.LinkString())
|
||||
}
|
||||
buf.WriteByte(']')
|
||||
buf.WriteString(suffix)
|
||||
return sym.Pkg.Lookup(buf.String())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue