]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix importing of method expressions
authorKeith Randall <khr@golang.org>
Tue, 13 Apr 2021 23:31:56 +0000 (16:31 -0700)
committerKeith Randall <khr@golang.org>
Wed, 14 Apr 2021 04:02:01 +0000 (04:02 +0000)
For OMETHEXPR, the Name in the Selection needs to be properly
linked up to the method declaration. Use the same code we
already have for ODOTMETH and OCALLPART to do that.

Fixes #45503

Change-Id: I7d6f886d606bae6faad8c104f50c177f871d41c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/309831
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dan Scales <danscales@google.com>
src/cmd/compile/internal/typecheck/iexport.go
src/cmd/compile/internal/typecheck/iimport.go
test/fixedbugs/issue45503.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue45503.dir/b.go [new file with mode: 0644]
test/fixedbugs/issue45503.go [new file with mode: 0644]

index 8f8931e4957e394e1b980df069825552b15b89b1..911d758083708228ceb0effed10a2154612d47bc 100644 (file)
@@ -1591,17 +1591,10 @@ func (w *exportWriter) expr(n ir.Node) {
                w.exoticSelector(n.Sel)
                if go117ExportTypes {
                        w.exoticType(n.Type())
-                       if n.Op() == ir.ODOT || n.Op() == ir.ODOTPTR || n.Op() == ir.ODOTINTER || n.Op() == ir.OMETHEXPR {
+                       if n.Op() == ir.ODOT || n.Op() == ir.ODOTPTR || n.Op() == ir.ODOTINTER {
                                w.exoticParam(n.Selection)
-                               if n.Op() == ir.OMETHEXPR {
-                                       name := ir.MethodExprName(n)
-                                       w.bool(name != nil)
-                                       if name != nil {
-                                               w.exoticType(name.Type())
-                                       }
-                               }
                        }
-                       // n.Selection is not required for ODOTMETH and OCALLPART. It will
+                       // n.Selection is not required for OMETHEXPR, ODOTMETH, and OCALLPART. It will
                        // be reconstructed during import.
                }
 
index 42c4619666656da05fe48eb8564c80c8fbfe673a..c55e3fbe2a0c61d1158823cf7da1740102820c0f 100644 (file)
@@ -1197,23 +1197,17 @@ func (r *importReader) node() ir.Node {
                pos := r.pos()
                expr := r.expr()
                sel := r.exoticSelector()
-               n := ir.NewSelectorExpr(pos, ir.OXDOT, expr, sel)
-               n.SetOp(op)
+               n := ir.NewSelectorExpr(pos, op, expr, sel)
                n.SetType(r.exoticType())
                switch op {
-               case ir.ODOT, ir.ODOTPTR, ir.ODOTINTER, ir.OMETHEXPR:
+               case ir.ODOT, ir.ODOTPTR, ir.ODOTINTER:
                        n.Selection = r.exoticParam()
-                       if op == ir.OMETHEXPR {
-                               if r.bool() { // has name
-                                       ir.MethodExprName(n).SetType(r.exoticType())
-                               }
-                       }
-               case ir.ODOTMETH, ir.OCALLPART:
+               case ir.ODOTMETH, ir.OCALLPART, ir.OMETHEXPR:
                        // 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 {
+                       if op == ir.OCALLPART || op == ir.OMETHEXPR {
                                // Lookdot clobbers the opcode and type, undo that.
                                n.SetOp(op)
                                n.SetType(typ)
diff --git a/test/fixedbugs/issue45503.dir/a.go b/test/fixedbugs/issue45503.dir/a.go
new file mode 100644 (file)
index 0000000..b45835b
--- /dev/null
@@ -0,0 +1,15 @@
+// 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 S struct{}
+
+func (s *S) M() {
+       s.m((*S).N)
+}
+
+func (s *S) N() {}
+
+func (s *S) m(func(*S)) {}
diff --git a/test/fixedbugs/issue45503.dir/b.go b/test/fixedbugs/issue45503.dir/b.go
new file mode 100644 (file)
index 0000000..df4877a
--- /dev/null
@@ -0,0 +1,12 @@
+// 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() {
+       s := a.S{}
+       s.M()
+}
diff --git a/test/fixedbugs/issue45503.go b/test/fixedbugs/issue45503.go
new file mode 100644 (file)
index 0000000..ab3b901
--- /dev/null
@@ -0,0 +1,10 @@
+// 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.
+
+// This test exercises exporting + importing method
+// expressions for use when inlining.
+
+package ignored