From: Russ Cox Date: Tue, 24 Mar 2009 01:32:37 +0000 (-0700) Subject: allow range on nil maps X-Git-Tag: weekly.2009-11-06~1984 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=86145611b0ad8c6ef6923f65f8a4fd39f07f69d7;p=gostls13.git allow range on nil maps R=ken OCL=26663 CL=26663 --- diff --git a/src/runtime/hashmap.c b/src/runtime/hashmap.c index bb8dd7ba98..b3022ca149 100644 --- a/src/runtime/hashmap.c +++ b/src/runtime/hashmap.c @@ -870,6 +870,10 @@ sys·mapassign2(Hmap *h, ...) void sys·mapiterinit(Hmap *h, struct hash_iter *it) { + if(h == nil) { + it->data = nil; + return; + } hash_iter_init(h, it); it->data = hash_next(it); if(debug) { diff --git a/test/map.go b/test/map.go index 085502bf52..95da48c75d 100644 --- a/test/map.go +++ b/test/map.go @@ -487,4 +487,10 @@ func main() { fmt.Printf("update mipM[%d][%d] = %i\n", i, i, mipM[i][i]); } } + + // test range on nil map + var mnil map[string] int; + for x, y := range mnil { + panic("range mnil"); + } }