From cb6cb42ede03d6a35fbe6603f22e8855910f9f51 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 20 May 2014 16:26:04 -0700 Subject: [PATCH] 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 --- src/pkg/reflect/all_test.go | 3 +++ src/pkg/runtime/hashmap.goc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go index 9c5eb4e554..e9949012c4 100644 --- a/src/pkg/reflect/all_test.go +++ b/src/pkg/reflect/all_test.go @@ -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) { diff --git a/src/pkg/runtime/hashmap.goc b/src/pkg/runtime/hashmap.goc index 36707c6ede..3327bed65e 100644 --- a/src/pkg/runtime/hashmap.goc +++ b/src/pkg/runtime/hashmap.goc @@ -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);