After reading https://golang.org/issues/27605 (proposal: report indexes for bounds failure), I started to wonder why we don't do something similar with nil pointer dereferences.
I've more than once found myself in a situation where I'm inspecting a nil pointer dereference panic and it ends up on a line where any number of variables could have been the nil pointer in question. It would be helpful in these circumstances to get a message like "attempt to dereference variable 'myvar', which is a nil pointer" or something along those lines. Here is a toy example that causes a panic on a line where there are many variables that could have been the problematic nil pointer. https://play.golang.com/p/mmkOOU3M3lU My guess as to why I've never seen this in a language before is because dereferencing doesn't always happen on a named variable. For example, `getSomePointer().field` could result in a nil pointer dereference, but there's no variable name to put in the panic. Maybe then the panic message would be "attempt to dereference anonymous variable, which is a nil pointer", which is still slightly less ambiguous than the current panic message. Do you think a feature like this could be useful, even with its inherent limitations? -- 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. For more options, visit https://groups.google.com/d/optout.