Commit 950a5689 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: fix method expressions with anonymous receivers

Method expressions with anonymous receiver types like "struct { T }.m"
require wrapper functions, which we weren't always creating. This in
turn resulted in linker errors.

This CL ensures that we generate wrapper functions for any anonymous
receiver types used in a method expression.

Fixes #22444.

Change-Id: Ia8ac27f238c2898965e57b82a91d959792d2ddd4
Reviewed-on: https://go-review.googlesource.com/105044
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 84b784a8
......@@ -1474,6 +1474,7 @@ func itabsym(it *obj.LSym, offset int64) *obj.LSym {
return syms[methodnum]
}
// addsignat ensures that a runtime type descriptor is emitted for t.
func addsignat(t *types.Type) {
signatset[t] = struct{}{}
}
......
......@@ -2378,6 +2378,16 @@ func looktypedot(n *Node, t *types.Type, dostrcmp int) bool {
return false
}
// The method expression T.m requires a wrapper when T is
// different from m's declared receiver type. We normally
// generate these wrappers while writing out runtime type
// descriptors, which is always done for types declared at
// package scope. However, we need to make sure to generate
// wrappers for anonymous receiver types too.
if mt.Sym == nil {
addsignat(t)
}
n.Sym = methodSym(t, n.Sym)
n.Xoffset = f2.Offset
n.Type = f2.Type
......
......@@ -45,10 +45,9 @@ func main() {
interface{ m1(string) }.m1(x, "d")
want += " m1(d)"
// cannot link the call below - see #22444
// g := struct{ T }.m2
// g(struct{T}{})
// want += " m2()"
g := struct{ T }.m2
g(struct{ T }{})
want += " m2()"
if got != want {
panic("got" + got + ", want" + want)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment