Commit cb6cb42e authored by Keith Randall's avatar Keith Randall

reflect: don't panic on delete from nil map.

Fixes #8051

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/95560046
parent a4366984
......@@ -993,6 +993,9 @@ func TestNilMap(t *testing.T) {
if x.Kind() != Invalid {
t.Errorf("mbig.MapIndex(\"hello\") for nil map = %v, want Invalid Value", x)
}
// Test that deletes from a nil map succeed.
mv.SetMapIndex(ValueOf("hi"), Value{})
}
func TestChan(t *testing.T) {
......
......@@ -990,7 +990,7 @@ func reflect·mapassign(t *MapType, h *Hmap, key *byte, val *byte) {
#pragma textflag NOSPLIT
func reflect·mapdelete(t *MapType, h *Hmap, key *byte) {
if(h == nil)
runtime·panicstring("delete from nil map");
return; // see bug 8051
if(raceenabled) {
runtime·racewritepc(h, runtime·getcallerpc(&t), reflect·mapdelete);
runtime·racereadobjectpc(key, t->key, runtime·getcallerpc(&t), reflect·mapdelete);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment