]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix method expression lookup during import
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 31 Aug 2021 17:18:13 +0000 (00:18 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 1 Sep 2021 02:16:30 +0000 (02:16 +0000)
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 #48088

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>
src/cmd/compile/internal/typecheck/iimport.go
test/fixedbugs/issue48088.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue48088.dir/b.go [new file with mode: 0644]
test/fixedbugs/issue48088.go [new file with mode: 0644]

index 45bf2563aa603c2018f611a2090f3deaa712cb80..7855702b020ef663322d72c8a329240db376ec6c 100644 (file)
@@ -1408,12 +1408,14 @@ func (r *importReader) node() ir.Node {
                                }
                        case ir.ODOT, ir.ODOTPTR, ir.ODOTINTER:
                                n.Selection = r.exoticField()
-                       case ir.ODOTMETH, ir.OMETHVALUE, ir.OMETHEXPR:
+                       case ir.OMETHEXPR:
+                               n = typecheckMethodExpr(n).(*ir.SelectorExpr)
+                       case ir.ODOTMETH, ir.OMETHVALUE:
                                // 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.OMETHVALUE || op == ir.OMETHEXPR {
+                               if op == ir.OMETHVALUE {
                                        // 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 (file)
index 0000000..2bb879d
--- /dev/null
@@ -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 (file)
index 0000000..221f2dd
--- /dev/null
@@ -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 (file)
index 0000000..b83fbd7
--- /dev/null
@@ -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