@@ -380,11 +380,14 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
380
380
return
381
381
}
382
382
383
- // renameTParams renames the type parameters in a function signature described by its
384
- // type and ordinary parameters (tparams and params) such that each type parameter is
385
- // given a new identity. renameTParams returns the new type and ordinary parameters.
383
+ // renameTParams renames the type parameters in the given type such that each type
384
+ // parameter is given a new identity. renameTParams returns the new type parameters
385
+ // and updated type. If the result type is unchanged from the argument type, none
386
+ // of the type parameters in tparams occurred in the type.
387
+ // If typ is a generic function, type parameters held with typ are not changed and
388
+ // must be updated separately if desired.
386
389
// The positions is only used for debug traces.
387
- func (check * Checker ) renameTParams (pos syntax.Pos , tparams []* TypeParam , params * Tuple ) ([]* TypeParam , * Tuple ) {
390
+ func (check * Checker ) renameTParams (pos syntax.Pos , tparams []* TypeParam , typ Type ) ([]* TypeParam , Type ) {
388
391
// For the purpose of type inference we must differentiate type parameters
389
392
// occurring in explicit type or value function arguments from the type
390
393
// parameters we are solving for via unification because they may be the
@@ -413,7 +416,7 @@ func (check *Checker) renameTParams(pos syntax.Pos, tparams []*TypeParam, params
413
416
// Type parameter renaming turns the first example into the second
414
417
// example by renaming the type parameter P into P2.
415
418
if len (tparams ) == 0 {
416
- return nil , params // nothing to do
419
+ return nil , typ // nothing to do
417
420
}
418
421
419
422
tparams2 := make ([]* TypeParam , len (tparams ))
@@ -428,7 +431,7 @@ func (check *Checker) renameTParams(pos syntax.Pos, tparams []*TypeParam, params
428
431
tparams2 [i ].bound = check .subst (pos , tparam .bound , renameMap , nil , check .context ())
429
432
}
430
433
431
- return tparams2 , check .subst (pos , params , renameMap , nil , check .context ()).( * Tuple )
434
+ return tparams2 , check .subst (pos , typ , renameMap , nil , check .context ())
432
435
}
433
436
434
437
// typeParamsString produces a string containing all the type parameter names
0 commit comments