From 584a2718d0d4cf637b0820ec67c3dddcb124cf73 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Wed, 1 Mar 2023 11:45:17 -0800 Subject: [PATCH] reflect: add type check to Value.Field() --- src/reflect/value.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/reflect/value.go b/src/reflect/value.go index 3f879e29..3e61c44a 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -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 != "" {