mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: prevent additional StructOf embedded method cases
The current implementation does not generate wrappers for methods of embedded non-interface types. We can only skip the wrapper if kindDirectIface of the generated struct type matches kindDirectIface of the embedded type. Panic if that is not the case. It would be better to actually generate wrappers, but that can be done later. Updates #15924 Fixes #24782 Change-Id: I01f5c76d9a07f44e1b04861bfe9f9916a04e65ca Reviewed-on: https://go-review.googlesource.com/121316 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
d144dd785f
commit
83092a40ac
2 changed files with 93 additions and 1 deletions
|
|
@ -2467,6 +2467,9 @@ func StructOf(fields []StructField) Type {
|
|||
// Issue 15924.
|
||||
panic("reflect: embedded type with methods not implemented if type is not first field")
|
||||
}
|
||||
if len(fields) > 1 {
|
||||
panic("reflect: embedded type with methods not implemented if there is more than one field")
|
||||
}
|
||||
for _, m := range unt.methods() {
|
||||
mname := ptr.nameOff(m.name)
|
||||
if mname.pkgPath() != "" {
|
||||
|
|
@ -2504,6 +2507,9 @@ func StructOf(fields []StructField) Type {
|
|||
// Issue 15924.
|
||||
panic("reflect: embedded type with methods not implemented if type is not first field")
|
||||
}
|
||||
if len(fields) > 1 && ft.kind&kindDirectIface != 0 {
|
||||
panic("reflect: embedded type with methods not implemented for non-pointer type")
|
||||
}
|
||||
for _, m := range unt.methods() {
|
||||
mname := ft.nameOff(m.name)
|
||||
if mname.pkgPath() != "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue