Warning for mixed value and pointer and receivers is flawed


The warning: "Struct Foo has methods on both value and pointer receivers. Such usage is not recommended by the Go Documentation."

The problem is if I have a struct with pointer receivers, I can't add a method like String() without triggering the warning.


Hey Peter,

We've discussed it on our Gophers Slack (#goland) and the warning doesn't make sense for Marshaler/Unmarshaler.

Please see and follow GO-13587.

If your case is different, please also comment on that issue with a code snippet to better understand which interfaces should be excluded from the inspection.

By the way, you can disable that inspection completely in Preferences | Editor | Inspections | Go | Probable bugs | Mixed value and pointer receivers.


Ah actually I realized that it was a problem with my code - I was using a struct with value receivers when I should have been using pointers. This prevented my implementation of String() from executing; instead it printed using the built-in/default stringer

I guess the warning actually helped!


Please sign in to leave a comment.