@@ -257,7 +257,7 @@ func expandNamed(env *Environment, n *Named, instPos token.Pos) (tparams *TypePa
257
257
// During type checking origm may not have a fully set up type, so defer
258
258
// instantiation of its signature until later.
259
259
m := NewFunc (origm .pos , origm .pkg , origm .name , nil )
260
- m .hasPtrRecv = origm . hasPtrRecv
260
+ m .hasPtrRecv = ptrRecv ( origm )
261
261
// Setting instRecv here allows us to complete later (we need the
262
262
// instRecv to get targs and the original method).
263
263
m .instRecv = n
@@ -289,32 +289,38 @@ func expandNamed(env *Environment, n *Named, instPos token.Pos) (tparams *TypePa
289
289
290
290
func (check * Checker ) completeMethod (env * Environment , m * Func ) {
291
291
assert (m .instRecv != nil )
292
- rtyp := m .instRecv
292
+ rbase := m .instRecv
293
293
m .instRecv = nil
294
294
m .setColor (black )
295
295
296
- assert (rtyp .TypeArgs ().Len () > 0 )
296
+ assert (rbase .TypeArgs ().Len () > 0 )
297
297
298
298
// Look up the original method.
299
- _ , orig := lookupMethod (rtyp .orig .methods , rtyp .obj .pkg , m .name )
299
+ _ , orig := lookupMethod (rbase .orig .methods , rbase .obj .pkg , m .name )
300
300
assert (orig != nil )
301
301
if check != nil {
302
302
check .objDecl (orig , nil )
303
303
}
304
304
origSig := orig .typ .(* Signature )
305
- if origSig .RecvTypeParams ().Len () != rtyp .targs .Len () {
305
+ if origSig .RecvTypeParams ().Len () != rbase .targs .Len () {
306
306
m .typ = origSig // or new(Signature), but we can't use Typ[Invalid]: Funcs must have Signature type
307
307
return // error reported elsewhere
308
308
}
309
309
310
- smap := makeSubstMap (origSig .RecvTypeParams ().list (), rtyp .targs .list ())
310
+ smap := makeSubstMap (origSig .RecvTypeParams ().list (), rbase .targs .list ())
311
311
sig := check .subst (orig .pos , origSig , smap , env ).(* Signature )
312
312
if sig == origSig {
313
- // No substitution occurred, but we still need to create a copy to hold the
314
- // instantiated receiver.
313
+ // No substitution occurred, but we still need to create a new signature to
314
+ // hold the instantiated receiver.
315
315
copy := * origSig
316
316
sig = & copy
317
317
}
318
+ var rtyp Type
319
+ if ptrRecv (m ) {
320
+ rtyp = NewPointer (rbase )
321
+ } else {
322
+ rtyp = rbase
323
+ }
318
324
sig .recv = NewParam (origSig .recv .pos , origSig .recv .pkg , origSig .recv .name , rtyp )
319
325
320
326
m .typ = sig
0 commit comments