mirror of
https://github.com/golang/go
synced 2024-11-26 08:27:56 -07:00
go/types: combine two loops (cleanup of TODO)
This is an exact port of CL 307949 to go/types. Change-Id: I796f3030a86d76deb80e58bb547460b586480911 Reviewed-on: https://go-review.googlesource.com/c/go/+/312096 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
5daefc5363
commit
f0a8101d34
@ -182,25 +182,14 @@ func (check *Checker) infer(posn positioner, tparams []*TypeName, targs []Type,
|
|||||||
// Use any untyped arguments to infer additional type arguments.
|
// Use any untyped arguments to infer additional type arguments.
|
||||||
// Some generic parameters with untyped arguments may have been given
|
// Some generic parameters with untyped arguments may have been given
|
||||||
// a type by now, we can ignore them.
|
// a type by now, we can ignore them.
|
||||||
j := 0
|
|
||||||
for _, i := range indices {
|
for _, i := range indices {
|
||||||
par := params.At(i)
|
par := params.At(i)
|
||||||
// Since untyped types are all basic (i.e., non-composite) types, an
|
// Since untyped types are all basic (i.e., non-composite) types, an
|
||||||
// untyped argument will never match a composite parameter type; the
|
// untyped argument will never match a composite parameter type; the
|
||||||
// only parameter type it can possibly match against is a *TypeParam.
|
// only parameter type it can possibly match against is a *TypeParam.
|
||||||
// Thus, only keep the indices of generic parameters that are not of
|
// Thus, only consider untyped arguments for generic parameters that
|
||||||
// composite types and which don't have a type inferred yet.
|
// are not of composite types and which don't have a type inferred yet.
|
||||||
if tpar, _ := par.typ.(*_TypeParam); tpar != nil && targs[tpar.index] == nil {
|
if tpar, _ := par.typ.(*_TypeParam); tpar != nil && targs[tpar.index] == nil {
|
||||||
indices[j] = i
|
|
||||||
j++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
indices = indices[:j]
|
|
||||||
|
|
||||||
// Unify parameter and default argument types for remaining generic parameters.
|
|
||||||
// TODO(gri) Rather than iterating again, combine this code with the loop above.
|
|
||||||
for _, i := range indices {
|
|
||||||
par := params.At(i)
|
|
||||||
arg := args[i]
|
arg := args[i]
|
||||||
targ := Default(arg.typ)
|
targ := Default(arg.typ)
|
||||||
// The default type for an untyped nil is untyped nil. We must not
|
// The default type for an untyped nil is untyped nil. We must not
|
||||||
@ -211,6 +200,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeName, targs []Type,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If we've got all type arguments, we're done.
|
// If we've got all type arguments, we're done.
|
||||||
targs, index = u.x.types()
|
targs, index = u.x.types()
|
||||||
|
Loading…
Reference in New Issue
Block a user