aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-09-01 00:18:13 +0700
committerCherry Mui <cherryyz@google.com>2021-09-01 16:46:29 +0000
commit396969420323bf52f120d842931dd8029e3fdf28 (patch)
tree6901e9cae845c0321c53ded37903288028f3857f
parent1dd24caf08985066b309af6bc461780c73e05c35 (diff)
downloadgo-396969420323bf52f120d842931dd8029e3fdf28.tar.gz
go-396969420323bf52f120d842931dd8029e3fdf28.zip
[release-branch.go1.17] cmd/compile: fix method expression lookup during import
CL 309831 fixed importing of method expressions, by re-using the same code already have for ODOTMETH. But that code does not work with embedded field. To fix this, we need to calculate all methods of the receiver base type of method expression, before looking up the selection. Fixes #48102 Change-Id: Ia244d36a3ed0f989735eb57becdfa70a81912f57 Reviewed-on: https://go-review.googlesource.com/c/go/+/346489 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/346670 Reviewed-by: Keith Randall <khr@golang.org>
-rw-r--r--src/cmd/compile/internal/typecheck/iimport.go6
-rw-r--r--test/fixedbugs/issue48088.dir/a.go22
-rw-r--r--test/fixedbugs/issue48088.dir/b.go11
-rw-r--r--test/fixedbugs/issue48088.go7
4 files changed, 44 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go
index 37f5a7bba0a..623916034ee 100644
--- a/src/cmd/compile/internal/typecheck/iimport.go
+++ b/src/cmd/compile/internal/typecheck/iimport.go
@@ -1222,12 +1222,14 @@ func (r *importReader) node() ir.Node {
switch op {
case ir.ODOT, ir.ODOTPTR, ir.ODOTINTER:
n.Selection = r.exoticField()
- case ir.ODOTMETH, ir.OCALLPART, ir.OMETHEXPR:
+ case ir.OMETHEXPR:
+ n = typecheckMethodExpr(n).(*ir.SelectorExpr)
+ case ir.ODOTMETH, ir.OCALLPART:
// These require a Lookup to link to the correct declaration.
rcvrType := expr.Type()
typ := n.Type()
n.Selection = Lookdot(n, rcvrType, 1)
- if op == ir.OCALLPART || op == ir.OMETHEXPR {
+ if op == ir.OCALLPART {
// Lookdot clobbers the opcode and type, undo that.
n.SetOp(op)
n.SetType(typ)
diff --git a/test/fixedbugs/issue48088.dir/a.go b/test/fixedbugs/issue48088.dir/a.go
new file mode 100644
index 00000000000..2bb879d557e
--- /dev/null
+++ b/test/fixedbugs/issue48088.dir/a.go
@@ -0,0 +1,22 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package a
+
+type T1 struct {
+ *T2
+}
+
+type T2 struct {
+}
+
+func (t2 *T2) M() {
+}
+
+func F() {
+ f(T1.M)
+}
+
+func f(f func(T1)) {
+}
diff --git a/test/fixedbugs/issue48088.dir/b.go b/test/fixedbugs/issue48088.dir/b.go
new file mode 100644
index 00000000000..221f2dde2a0
--- /dev/null
+++ b/test/fixedbugs/issue48088.dir/b.go
@@ -0,0 +1,11 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package b
+
+import "a"
+
+func F() {
+ a.F()
+}
diff --git a/test/fixedbugs/issue48088.go b/test/fixedbugs/issue48088.go
new file mode 100644
index 00000000000..b83fbd7af16
--- /dev/null
+++ b/test/fixedbugs/issue48088.go
@@ -0,0 +1,7 @@
+// compiledir
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ignored