Skip to content

Commit 04a44d2

Browse files
tsharapovgopherbot
authored andcommitted
_content/doc/faq: clarify the explanation of method sets
I had a small discussion with @ianlancetaylor here: https://groups.google.com/g/golang-nuts/c/uon32LDerjM/m/dvg0mxbwAAAJ?utm_medium=email&utm_source=footer I would like to clarify this entry about method sets a bit because the current explanation is a bit confusing. I believe there is no reason for the Write method of Buffer to use a value receiver. In this case, the sentence about the compiler's ability to implicitly take addresses doesn't make sense. What I believe is implied here is a hypothetical situation where the code from the example is allowed by Go, and then it is noted that this makes no sense as the result would be lost in the caller. Change-Id: Ie4de77364165d59178e2b1e6e1393370e06d1755 GitHub-Last-Rev: 40392d4 GitHub-Pull-Request: #296 Reviewed-on: https://go-review.googlesource.com/c/website/+/601996 Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent d2408a1 commit 04a44d2

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

_content/doc/faq.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -1425,19 +1425,17 @@ the language specification.)
14251425
Even in cases where the compiler could take the address of a value
14261426
to pass to the method, if the method modifies the value the changes
14271427
will be lost in the caller.
1428-
As an example, if the `Write` method of
1429-
[`bytes.Buffer`](/pkg/bytes/#Buffer)
1430-
used a value receiver rather than a pointer,
1431-
this code:
1428+
1429+
As an example, if the code below were valid:
14321430

14331431
```
14341432
var buf bytes.Buffer
14351433
io.Copy(buf, os.Stdin)
14361434
```
14371435

1438-
would copy standard input into a *copy* of `buf`,
1436+
it would copy standard input into a *copy* of `buf`,
14391437
not into `buf` itself.
1440-
This is almost never the desired behavior.
1438+
This is almost never the desired behavior and is therefore disallowed by the language.
14411439

14421440
### What happens with closures running as goroutines? {#closures_and_goroutines}
14431441

0 commit comments

Comments
 (0)