Ah, thanks Ian, that's exactly the kind of requirement I was looking for. (also, you said "without" but you probably meant "while")
Perhaps this is a job for "go vet". And/or, looks like staticcheck.io has a check I can try: https://staticcheck.io/docs/checks#SA5000 On Monday, September 23, 2019 at 9:45:37 PM UTC-7, Ian Lance Taylor wrote: > > On Mon, Sep 23, 2019 at 2:40 PM abuchanan via golang-nuts > <golan...@googlegroups.com <javascript:>> wrote: > > > > Is there anything written down on why assignment to a nil map causes a > panic? I'm curious if there were carefully considered tradeoffs while > making this decision. > > > > Assignment to nil maps has caused most of the unexpected panics I've > seen. Many times these happen in production and cause an incident. Every > time it happens I think, "we've got to do something about this." > > > > I'm not sure what the best solution is yet, but there must be something > better than the status quo. Would it be possible to have assignments > automatically initialize a nil map? > > I agree that this is awkward. But we've never been able to think of a > way to make an assignment to a nil map initialize the map without also > preserving the very useful property that the zero value of any Go type > can be represented by a sequence of zero bytes. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d9cc8fb3-7d73-48c0-8c60-9d9b1022054c%40googlegroups.com.