mirror of
https://github.com/golang/go
synced 2024-11-22 16:44:54 -07:00
reflect: improve panic when MapIter has no associated map Value
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>
This commit is contained in:
parent
1b2d794ca3
commit
7619a4528d
@ -1686,6 +1686,9 @@ func (it *MapIter) SetValue(dst Value) {
|
||||
// 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user