}
}
+ // Rename type parameters to avoid problems with recursive instantiations.
// Note that NewTuple(params...) below is nil if len(params) == 0, as desired.
- targs = check.infer(pos, sig.TypeParams().list(), targs, NewTuple(params...), args)
+ tparams, params2 := check.renameTParams(pos, sig.TypeParams().list(), NewTuple(params...))
+
+ targs = check.infer(pos, tparams, targs, params2, args)
if targs == nil {
// error was already reported
x.mode = invalid
check.versionErrorf(call.Pos(), "go1.18", "implicit function instantiation")
}
}
- targs := check.infer(call.Pos(), sig.TypeParams().list(), targs, sigParams, args)
+
+ // Rename type parameters to avoid problems with recursive calls.
+ var tparams []*TypeParam
+ tparams, sigParams = check.renameTParams(call.Pos(), sig.TypeParams().list(), sigParams)
+
+ targs := check.infer(call.Pos(), tparams, targs, sigParams, args)
if targs == nil {
return // error already reported
}
// need to compute it from the adjusted list; otherwise we can
// simply use the result signature's parameter list.
if adjusted {
- sigParams = check.subst(call.Pos(), sigParams, makeSubstMap(sig.TypeParams().list(), targs), nil, check.context()).(*Tuple)
+ sigParams = check.subst(call.Pos(), sigParams, makeSubstMap(tparams, targs), nil, check.context()).(*Tuple)
} else {
sigParams = rsig.params
}
}
// len(targs) < n
- // Rename type parameters to avoid conflicts in recursive instantiation scenarios.
- tparams, params = check.renameTParams(pos, tparams, params)
-
- if traceInference {
- check.dump("-- rename: %s%s ➞ %s\n", tparams, params, targs)
- }
-
// Make sure we have a "full" list of type arguments, some of which may
// be nil (unknown). Make a copy so as to not clobber the incoming slice.
if len(targs) < n {
// renameTParams renames the type parameters in a function signature described by its
// type and ordinary parameters (tparams and params) such that each type parameter is
// given a new identity. renameTParams returns the new type and ordinary parameters.
+// The positions is only used for debug traces.
func (check *Checker) renameTParams(pos syntax.Pos, tparams []*TypeParam, params *Tuple) ([]*TypeParam, *Tuple) {
// For the purpose of type inference we must differentiate type parameters
// occurring in explicit type or value function arguments from the type
//
// Type parameter renaming turns the first example into the second
// example by renaming the type parameter P into P2.
+ if len(tparams) == 0 {
+ return nil, params // nothing to do
+ }
+
tparams2 := make([]*TypeParam, len(tparams))
for i, tparam := range tparams {
tname := NewTypeName(tparam.Obj().Pos(), tparam.Obj().Pkg(), tparam.Obj().Name(), nil)
}
}
+ // Rename type parameters to avoid problems with recursive instantiations.
// Note that NewTuple(params...) below is nil if len(params) == 0, as desired.
- targs = check.infer(atPos(pos), sig.TypeParams().list(), targs, NewTuple(params...), args)
+ tparams, params2 := check.renameTParams(pos, sig.TypeParams().list(), NewTuple(params...))
+
+ targs = check.infer(atPos(pos), tparams, targs, params2, args)
if targs == nil {
// error was already reported
x.mode = invalid
check.softErrorf(inNode(call, call.Lparen), UnsupportedFeature, "implicit function instantiation requires go1.18 or later")
}
}
- targs := check.infer(call, sig.TypeParams().list(), targs, sigParams, args)
+
+ // Rename type parameters to avoid problems with recursive calls.
+ var tparams []*TypeParam
+ tparams, sigParams = check.renameTParams(call.Pos(), sig.TypeParams().list(), sigParams)
+
+ targs := check.infer(call, tparams, targs, sigParams, args)
if targs == nil {
return // error already reported
}
// need to compute it from the adjusted list; otherwise we can
// simply use the result signature's parameter list.
if adjusted {
- sigParams = check.subst(call.Pos(), sigParams, makeSubstMap(sig.TypeParams().list(), targs), nil, check.context()).(*Tuple)
+ sigParams = check.subst(call.Pos(), sigParams, makeSubstMap(tparams, targs), nil, check.context()).(*Tuple)
} else {
sigParams = rsig.params
}
}
// len(targs) < n
- // Rename type parameters to avoid conflicts in recursive instantiation scenarios.
- tparams, params = check.renameTParams(posn.Pos(), tparams, params)
-
- if traceInference {
- check.dump("-- rename: %s%s ➞ %s\n", tparams, params, targs)
- }
-
// Make sure we have a "full" list of type arguments, some of which may
// be nil (unknown). Make a copy so as to not clobber the incoming slice.
if len(targs) < n {
// renameTParams renames the type parameters in a function signature described by its
// type and ordinary parameters (tparams and params) such that each type parameter is
// given a new identity. renameTParams returns the new type and ordinary parameters.
+// The positions is only used for debug traces.
func (check *Checker) renameTParams(pos token.Pos, tparams []*TypeParam, params *Tuple) ([]*TypeParam, *Tuple) {
// For the purpose of type inference we must differentiate type parameters
// occurring in explicit type or value function arguments from the type
//
// Type parameter renaming turns the first example into the second
// example by renaming the type parameter P into P2.
+ if len(tparams) == 0 {
+ return nil, params // nothing to do
+ }
+
tparams2 := make([]*TypeParam, len(tparams))
for i, tparam := range tparams {
tname := NewTypeName(tparam.Obj().Pos(), tparam.Obj().Pkg(), tparam.Obj().Name(), nil)