Skip to content

Commit

Permalink
reflect: skip duplicate check in StructOf when the name of a field is…
Browse files Browse the repository at this point in the history
… "_"

Fixes #49110

Change-Id: I32c2cb26cca067a4a676ce4bbc3e51f1e0cdb259
Reviewed-on: https://go-review.googlesource.com/c/go/+/357959
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dan Kortschak <dan@kortschak.io>
Reviewed-by: Sebastien Binet <s@sbinet.org>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
  • Loading branch information
zhouguangyuan0718 authored and ianlancetaylor committed Oct 27, 2021
1 parent de1abf7 commit a3c4ac0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/reflect/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ func StructOf(fields []StructField) Type {
}
}
}
if _, dup := fset[name]; dup {
if _, dup := fset[name]; dup && name != "_" {
panic("reflect.StructOf: duplicate field " + name)
}
fset[name] = struct{}{}
Expand Down
16 changes: 16 additions & 0 deletions test/fixedbugs/issue49110.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// run

// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import "reflect"

func main() {
_ = reflect.StructOf([]reflect.StructField{
{Name: "_", PkgPath: "main", Type: reflect.TypeOf(int(0))},
{Name: "_", PkgPath: "main", Type: reflect.TypeOf(int(0))},
})
}

0 comments on commit a3c4ac0

Please sign in to comment.