reflect: add type check to Value.Field()

This commit is contained in:
Damian Gryski
2023-03-01 11:45:17 -08:00
committed by Damian Gryski
parent 069c397975
commit 584a2718d0
+3
View File
@@ -568,6 +568,9 @@ func (v Value) Elem() Value {
// Field returns the value of the i'th field of this struct.
func (v Value) Field(i int) Value {
if v.Kind() != Struct {
panic(&ValueError{Method: "Field", Kind: v.Kind()})
}
structField := v.typecode.rawField(i)
flags := v.flags
if structField.PkgPath != "" {