It's been discussed a bunch of times - the main argument against remains that "nil" is not a special value and can be a perfectly reasonable implementation of an interface. For example, `sort.StringSlice(nil)` is a perfectly fine implementation of `sort.Interface` (the same, of course, for any other slice type you might implement `sort.Interface` for yourself). I.e. there is nothing *inherently* wrong putting a `nil` concrete value into an interface to make a non-nil interface. And as vet errs on the side of caution (and also, because TBQH it seems useless to specifically initialize a slice with an empty slice just to satisfy vet), there shouldn't be vet-checks with (likely) false positives.
I think it *might* be possible to write a careful vet-check that avoids false positives and can still help catch some of the bugs. If you find an assignment of a definitely-nil-value to an interface, you could check the methods of that concrete type whether they panic when the receiver is nil (i.e. if they dereference it). This wouldn't have false positives, but should catch most interesting and simple cases. If that sounds interesting, I would recommend trying to implement that as a tool out-of-tree, to give the community opportunity to test it out. If you base it on the analysis <https://godoc.org/golang.org/x/tools/go/analysis> package, it would be easy to integrate into other tools (and maybe eventually vet) when the time comes :) On Thu, Jun 27, 2019 at 4:20 PM Burak Serdar <bser...@ieee.org> wrote: > This happened to me more than once, and not only with errors. > > For a function that is declared to return an interface, if you return > a nil-pointer with a type other than that interface, the returned > interface is not nil. > > Here's an example: > > https://play.golang.org/p/dpd76zyN9Fv > > I think go vet should warn about this case. What do you think? > > -- > 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/CAMV2RqrpdCa4t6VrBrkbU%3DrbdNhC_oz%2BusTD9PA6VgCb%3D2SXJw%40mail.gmail.com > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAEkBMfEPKjRXnOjZNXwDDXeUDv0sBe357KqT%3DA%2B2cJTp8rbdNA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.