aboutsummaryrefslogtreecommitdiff
path: root/test/method7.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-01-24 09:59:20 -0800
committerDan Scales <danscales@google.com>2021-01-26 17:05:06 +0000
commit08a598f8c1c123fda3b7ad30659fa05a8be1ccde (patch)
treebab7a41df3b1819b7c0bd19900607247d01ed0ff /test/method7.go
parentcecc1dfcba15a06a06a7f3ea79e809e95c166c25 (diff)
downloadgo-08a598f8c1c123fda3b7ad30659fa05a8be1ccde.tar.gz
go-08a598f8c1c123fda3b7ad30659fa05a8be1ccde.zip
[dev.typeparams] cmd/compile: fix MethodExpr handling with embedded fields
The recent refactoring of SelectorExpr code to helpers broke the handling of MethodExprs when there is an embedded field involved (e.g. test/method7.go, line 48). If there is an embedded field involved, the node op seen in DotMethod() is an ODOT rather than an OTYPE. Also, the receiver type of the result should be the original type, but the new code was using the last type after following the embedding path. Change-Id: I13f7ea6448b03d3e8f974103ee3a027219ca8388 Reviewed-on: https://go-review.googlesource.com/c/go/+/286176 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/method7.go')
-rw-r--r--test/method7.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/method7.go b/test/method7.go
index 15e123e85f..05accb3ee0 100644
--- a/test/method7.go
+++ b/test/method7.go
@@ -25,6 +25,11 @@ type T int
func (T) m2() { got += " m2()" }
+type Outer struct{ *Inner }
+type Inner struct{ s string }
+
+func (i Inner) M() string { return i.s }
+
func main() {
// method expressions with named receiver types
I.m(S{})
@@ -52,4 +57,11 @@ func main() {
if got != want {
panic("got" + got + ", want" + want)
}
+
+ h := (*Outer).M
+ got := h(&Outer{&Inner{"hello"}})
+ want := "hello"
+ if got != want {
+ panic("got " + got + ", want " + want)
+ }
}