}{
{"func (r T[P]) m() P", "func (T[int]).m() int"},
{"func (r T[P]) m(P)", "func (T[int]).m(int)"},
- {"func (r T[P]) m() func() P", "func (T[int]).m() func() int"},
+ {"func (r *T[P]) m(P)", "func (*T[int]).m(int)"},
{"func (r T[P]) m() T[P]", "func (T[int]).m() T[int]"},
{"func (r T[P]) m(T[P])", "func (T[int]).m(T[int])"},
{"func (r T[P]) m(T[P], P, string)", "func (T[int]).m(T[int], int, string)"},
if err != nil {
t.Fatal(err)
}
- typ := pkg.Scope().Lookup("X").Type().(*Named)
+ typ := NewPointer(pkg.Scope().Lookup("X").Type())
obj, _, _ := LookupFieldOrMethod(typ, false, pkg, "m")
m, _ := obj.(*Func)
if m == nil {
// During type checking origm may not have a fully set up type, so defer
// instantiation of its signature until later.
m := NewFunc(origm.pos, origm.pkg, origm.name, nil)
- m.hasPtrRecv = origm.hasPtrRecv
+ m.hasPtrRecv = ptrRecv(origm)
// Setting instRecv here allows us to complete later (we need the
// instRecv to get targs and the original method).
m.instRecv = n
func (check *Checker) completeMethod(env *Environment, m *Func) {
assert(m.instRecv != nil)
- rtyp := m.instRecv
+ rbase := m.instRecv
m.instRecv = nil
m.setColor(black)
- assert(rtyp.TypeArgs().Len() > 0)
+ assert(rbase.TypeArgs().Len() > 0)
// Look up the original method.
- _, orig := lookupMethod(rtyp.orig.methods, rtyp.obj.pkg, m.name)
+ _, orig := lookupMethod(rbase.orig.methods, rbase.obj.pkg, m.name)
assert(orig != nil)
if check != nil {
check.objDecl(orig, nil)
}
origSig := orig.typ.(*Signature)
- if origSig.RecvTypeParams().Len() != rtyp.targs.Len() {
+ if origSig.RecvTypeParams().Len() != rbase.targs.Len() {
m.typ = origSig // or new(Signature), but we can't use Typ[Invalid]: Funcs must have Signature type
return // error reported elsewhere
}
- smap := makeSubstMap(origSig.RecvTypeParams().list(), rtyp.targs.list())
+ smap := makeSubstMap(origSig.RecvTypeParams().list(), rbase.targs.list())
sig := check.subst(orig.pos, origSig, smap, env).(*Signature)
if sig == origSig {
- // No substitution occurred, but we still need to create a copy to hold the
- // instantiated receiver.
+ // No substitution occurred, but we still need to create a new signature to
+ // hold the instantiated receiver.
copy := *origSig
sig = ©
}
+ var rtyp Type
+ if ptrRecv(m) {
+ rtyp = NewPointer(rbase)
+ } else {
+ rtyp = rbase
+ }
sig.recv = NewParam(origSig.recv.pos, origSig.recv.pkg, origSig.recv.name, rtyp)
m.typ = sig