golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.7k stars 17.5k forks source link

reflect: SetMapIndex should not panic on a nil map delete #8051

Closed randall77 closed 9 years ago

randall77 commented 10 years ago
package main

import "reflect"

func main() {
    var m map[int]int
    delete(m, 5)

    v := reflect.ValueOf(m)
    v.SetMapIndex(reflect.ValueOf(5), reflect.Value{})
}

The first two lines succeed with no panic, as they should.
The second two lines panic with "delete from nil map".
They should silently succeed instead, like the non-reflect version.
randall77 commented 10 years ago

Comment 1:

This issue was closed by revision cb6cb42ede03d6a35fbe6603f22e8855910f9f5.

Status changed to Fixed.

gopherbot commented 10 years ago

Comment 2:

CL https://golang.org/cl/96540051 mentions this issue.