> On Nov 15, 2023, at 7:08 AM, 'Brian Candler' via golang-nuts 
> <golang-nuts@googlegroups.com> wrote:
> 
> On Tuesday, 14 November 2023 at 03:38:04 UTC Mike Schinkel wrote:
> 1. A value variable and multiple value receivers  <--- compiles
> 2. A pointer variable and multiple value receivers <--- compiles
> 3. A pointer variable and multiple pointer receivers.  <--- compiles 
> 4. A value variable and multiple pointer receivers.  <--- will NOT compile
> 5. A pointer variable and mixed value+pointer receivers  <--- compiles 
> 6. A value variable and mixed value+pointer receivers. <--- will NOT compile
> 
> Permutation #4 and #6 are consistent with the description above, and they 
> both have a value variable in common.
> 
> However, given than #5 DOES compile, I was left wondering why the standard 
> that mixed receivers should be flagged as an error? 
> 
> I am not sure that "the standard" is for mixed receivers to be flagged as an 
> error. Can you give a specific example of where the standard Go toolchain 
> does this?

Thanks for asking.

In hindsight I was in-artful in my use of words. I should not have said 
"flagged as an error" even though that is what GoLand does.  I should have 
instead asked why the Go FAQ 
<https://go.dev/doc/faq#methods_on_values_or_pointers> advised to use all 
pointer receivers when there are any pointer receivers:

> Next is consistency. If some of the methods of the type must have pointer 
> receivers, the rest should too, so the method set is consistent regardless of 
> how the type is used. See the section on method sets 
> <https://go.dev/doc/faq#different_method_sets> for details.

BTW, I am assuming that GoLand flags mixed receivers as a concern because of 
what the Go FAQ recommends.

-Mike

> Is this question really about Goland, a third-party product, and/or some 
> underlying third-party linter that it uses?  If so, it's an issue for that 
> third party.
> 
> Arguably it's not great style to do this, and it might make it confusing for 
> users of your package. But it's not an error, either for the compiler or "go 
> vet". https://go.dev/play/p/fBgrltIEjA2
> 
> -- 
> 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 
> <mailto:golang-nuts+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/4fe6a954-696c-40f1-86cf-ea9148e42ba2n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/4fe6a954-696c-40f1-86cf-ea9148e42ba2n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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/470BA5FB-72A9-4E00-A01C-CA8D4D9ED631%40newclarity.net.

Reply via email to