diff options
author | Keith Randall <khr@golang.org> | 2021-04-13 16:31:56 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2021-04-14 04:02:01 +0000 |
commit | 6d8ba77896d05720e1cb1728c27db60926e672b5 (patch) | |
tree | c871ac85f8407be5df6b830df4fa8d6e57371131 /src/cmd | |
parent | e7ab1a5ba83cd013af24b011d9d3a88dc5b05c07 (diff) | |
download | go-6d8ba77896d05720e1cb1728c27db60926e672b5.tar.gz go-6d8ba77896d05720e1cb1728c27db60926e672b5.zip |
cmd/compile: fix importing of method expressions
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>
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/compile/internal/typecheck/iexport.go | 11 | ||||
-rw-r--r-- | src/cmd/compile/internal/typecheck/iimport.go | 14 |
2 files changed, 6 insertions, 19 deletions
diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go index 8f8931e495..911d758083 100644 --- a/src/cmd/compile/internal/typecheck/iexport.go +++ b/src/cmd/compile/internal/typecheck/iexport.go @@ -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. } diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go index 42c4619666..c55e3fbe2a 100644 --- a/src/cmd/compile/internal/typecheck/iimport.go +++ b/src/cmd/compile/internal/typecheck/iimport.go @@ -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) |