diff options
| author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2022-07-23 22:31:35 +0700 |
|---|---|---|
| committer | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2022-08-11 19:05:54 +0000 |
| commit | 62654dfd4f8d7ac2309232dc3c09c33b1741ce95 (patch) | |
| tree | 68ff8259ce7430de789dda13036c8205c1ea93c0 /src/cmd/compile/internal/noder | |
| parent | 9e4638ad20181ba4c3b1985da48c56be121901fb (diff) | |
| download | go-62654dfd4f8d7ac2309232dc3c09c33b1741ce95.tar.xz | |
cmd/compile: fix wrong typeparams for selector expr with embedded generic type
For selector expression "x.M" where "M" is a promoted method, irgen is using
the type of receiver "x" for determining the typeparams for instantiation.
However, because M is a promoted method, so its associated receiver is
not "x", but "x.T" where "T" is the embedded field of "x". That casues a
mismatch when converting non-shape types arguments.
Fixing it by using the actual receiver which has the method, instead of
using the base receiver.
Fixes #53982
Change-Id: I1836fc422d734df14e9e6664d4bd014503960bfc
Reviewed-on: https://go-review.googlesource.com/c/go/+/419294
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder')
| -rw-r--r-- | src/cmd/compile/internal/noder/stencil.go | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index d3f51e00cd..6fcb31b472 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -334,10 +334,6 @@ func (g *genInst) buildClosure(outer *ir.Func, x ir.Node) ir.Node { } else { // ir.OMETHEXPR or ir.METHVALUE // Method expression T.M where T is a generic type. se := x.(*ir.SelectorExpr) - targs := deref(se.X.Type()).RParams() - if len(targs) == 0 { - panic("bad") - } if x.Op() == ir.OMETHVALUE { rcvrValue = se.X } @@ -348,7 +344,8 @@ func (g *genInst) buildClosure(outer *ir.Func, x ir.Node) ir.Node { // of se.Selection, since that will be the type that actually has // the method. recv := deref(se.Selection.Type.Recv().Type) - if len(recv.RParams()) == 0 { + targs := recv.RParams() + if len(targs) == 0 { // The embedded type that actually has the method is not // actually generic, so no need to build a closure. return x |
