mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: for godefs, don't let field prefix removal cause duplicates
Fixes #48396 Change-Id: Idd7cb66536ef513806c472d394a929bc271fc26b Reviewed-on: https://go-review.googlesource.com/c/go/+/350159 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
parent
4efdaa7bc7
commit
265b59aefd
4 changed files with 47 additions and 0 deletions
|
|
@ -3030,6 +3030,31 @@ func upper(s string) string {
|
|||
// so that all fields are exported.
|
||||
func godefsFields(fld []*ast.Field) {
|
||||
prefix := fieldPrefix(fld)
|
||||
|
||||
// Issue 48396: check for duplicate field names.
|
||||
if prefix != "" {
|
||||
names := make(map[string]bool)
|
||||
fldLoop:
|
||||
for _, f := range fld {
|
||||
for _, n := range f.Names {
|
||||
name := n.Name
|
||||
if name == "_" {
|
||||
continue
|
||||
}
|
||||
if name != prefix {
|
||||
name = strings.TrimPrefix(n.Name, prefix)
|
||||
}
|
||||
name = upper(name)
|
||||
if names[name] {
|
||||
// Field name conflict: don't remove prefix.
|
||||
prefix = ""
|
||||
break fldLoop
|
||||
}
|
||||
names[name] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
npad := 0
|
||||
for _, f := range fld {
|
||||
for _, n := range f.Names {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue