From aeec6dbfe009f371021bddba13e2eb18e5d1a469 Mon Sep 17 00:00:00 2001
From: Cuong Manh Le
Date: Sun, 22 Aug 2021 12:07:14 +0700
Subject: [PATCH] spec: add example for method value in case of embedded method
So it's clear to the reader that if "M" is a promoted method from
embedded field "T", then "x.M" will be expanded to "x.T.M" during the
evaluation of the method value.
Fixes #47863
Change-Id: Id3b82127a2054584b6842c487f6e15c3102dc9fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/344209
Trust: Cuong Manh Le
Run-TryBot: Cuong Manh Le
TryBot-Result: Go Bot
Reviewed-by: Rob Pike
Reviewed-by: Matthew Dempsky
---
doc/go_spec.html | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/doc/go_spec.html b/doc/go_spec.html
index fd5fee46eb2..22b616134ac 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
@@ -3000,6 +3000,18 @@ method value; the saved copy is then used as the receiver in any calls,
which may be executed later.
+
+type S struct { *T }
+type T int
+func (t T) M() { print(t) }
+
+t := new(T)
+s := S{T: t}
+f := t.M // receiver *t is evaluated and stored in f
+g := s.M // receiver *(s.T) is evaluated and stored in g
+*t = 42 // does not affect stored receivers in f and g
+
+
The type T
may be an interface or non-interface type.