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: Brad Fitzpatrick <bradfitz@golang.org>
return syms[methodnum]
}
+// addsignat ensures that a runtime type descriptor is emitted for t.
func addsignat(t *types.Type) {
signatset[t] = struct{}{}
}
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
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)