reflect: add type check to Value.Field()

Этот коммит содержится в:
Damian Gryski 2023-03-01 11:45:17 -08:00 коммит произвёл Damian Gryski
родитель 069c397975
коммит 584a2718d0

Просмотреть файл

@ -568,6 +568,9 @@ func (v Value) Elem() Value {
// Field returns the value of the i'th field of this struct. // Field returns the value of the i'th field of this struct.
func (v Value) Field(i int) Value { func (v Value) Field(i int) Value {
if v.Kind() != Struct {
panic(&ValueError{Method: "Field", Kind: v.Kind()})
}
structField := v.typecode.rawField(i) structField := v.typecode.rawField(i)
flags := v.flags flags := v.flags
if structField.PkgPath != "" { if structField.PkgPath != "" {