it := new(reflect.MapIter)
it.Next()
This generates a nil pointer dereference panic from reflect.Value.pointer.
Generate a clearer panic.
For #46293
Change-Id: I32a22c797e1ba3a7b4e70b38ceb4dedb44d264fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/321890
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
// entry. It returns false when the iterator is exhausted; subsequent
// calls to Key, Value, or Next will panic.
func (it *MapIter) Next() bool {
+ if !it.m.IsValid() {
+ panic("MapIter.Next called on an iterator that does not have an associated map Value")
+ }
if !it.hiter.initialized() {
mapiterinit(it.m.typ, it.m.pointer(), &it.hiter)
} else {