I ran into the following runtime error while attempting access an empty struct value that had been appended to an uninitialised slice: https://play.golang.org/p/J2ItiISh2f,
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0xffffffff addr=0x0 pc=0x202e2]
The append (line 11) succeeds, as does printing the slice as a whole (line 12); accessing the appended struct via range (line 16) yields a panic. Issue encountered under 1.4.1; unable to replicate under gccgo.
Known workaround: comment out line 8 in favour of 9 and make an empty slice explicitly (yuck).
The following also work as expected, though they alter intended behaviour:
- Modifying the struct to include a single field, allowing for default initialisation
- Taking a slice of pointers []*empty