Skip to content

Commit 742dd1e

Browse files
committed
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 golang#46293 Change-Id: I32a22c797e1ba3a7b4e70b38ceb4dedb44d264fa
1 parent e3c2271 commit 742dd1e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/reflect/value.go

+3
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,9 @@ func (it *MapIter) SetValue(dst Value) {
13421342
// entry. It returns false when the iterator is exhausted; subsequent
13431343
// calls to Key, Value, or Next will panic.
13441344
func (it *MapIter) Next() bool {
1345+
if !it.m.IsValid() {
1346+
panic("MapIter.Next called on an iterator that does not have an associated map Value")
1347+
}
13451348
if it.it == nil {
13461349
it.it = unsafe.Pointer(&it.hiter)
13471350
mapiterinit(it.m.typ, it.m.pointer(), it.it)

0 commit comments

Comments
 (0)