https://dave.cheney.net/2015/11/18/wednesday-pop-quiz-spot-the-race
It is a data race because calling rpc.version() makes a copy of rpc,
which causes reading the field rpc.result concurrently while it is
being written by the goroutine.
I do not agree that this is because how the compiler works. A value
receiver is equivalent to pass-by-value argument, that is:
rcp.version()
is equivalent to:
RPC.version(rpc)
thus, creating the copy of the rpc variable. So, the compiler may
choose to avoid the race by not copying it, or by inlining the version
function, but according to the spec, it is passed by value, i.e., it
is copied.
On Nov 14, 2023, at 8:36 PM, Mike Schinkel <mi...@newclarity.net> wrote:
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/8f46fecc-1d5f-4507-8209-76adef294bafn%40googlegroups.com.
On Nov 15, 2023, at 7:08 AM, 'Brian Candler' via golang-nuts <golan...@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?
> 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 for details.
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...@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.
> The first is so that the method can modify the value that its receiver points to.
> The second is to avoid copying the value on each method call. This can be more efficient if the receiver is a large struct, for example.
Lads, I guess this entry and the subsequent entries are very important regarding the discussion.Also we shall recall that T and *T are different types.Golang performs some implicit conversions in order to make the code more readable when we use the methods "directly" on a concrete type, but when we use interfaces there is no implicit conversion. I guess this entry has key information about this affair.
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/Qb4IAEbpziU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9f7c1d63-aa73-41a8-aeaf-1b191bec4cebn%40googlegroups.com.