fjl / gencodec

Command gencodec generates marshaling methods for Go struct types.
MIT License
55 stars 27 forks source link

Help needed #6

Closed vidmed closed 5 years ago

vidmed commented 6 years ago

Could you please explain me for what purpose do you use this function func writeUseOfOverride(w io.Writer, n *types.Named, qf types.Qualifier) { name := types.TypeString(types.NewPointer(n), qf) fmt.Fprintf(w, "var _ = (%s)(nil)\n", name) } This generates line like this var _ = (*txdataMarshaling)(nil) For what purpose this instruction needed? Thanks for your help beforehand

fjl commented 5 years ago

The override type definition is usually only needed for gencodec. Running golint or staticcheck can mark this type definition as unused. writeUseOfOverride just ensures that the override type is used so that linters don't report it as unused.