reflect: make Field panic when out of bounds, as documented

Fixes #15046.

Change-Id: Iba7216297735be8e1ec550ce5336d17dcd3fd6b7
Reviewed-on: https://go-review.googlesource.com/22992
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Emmanuel Odeke 2016-05-10 07:06:47 -07:00 committed by Brad Fitzpatrick
parent 42b647bde6
commit 9edb27e76f
2 changed files with 36 additions and 1 deletions

View file

@ -1178,7 +1178,7 @@ func (tag StructTag) Lookup(key string) (value string, ok bool) {
// Field returns the i'th struct field.
func (t *structType) Field(i int) (f StructField) {
if i < 0 || i >= len(t.fields) {
return
panic("reflect: Field index out of bounds")
}
p := &t.fields[i]
f.Type = toType(p.typ)