mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
go/types: minor cleanup of writeTParamList
This is a port of CL 339903 to go/types. Change-Id: Iaf5fe7321d907df4421128c66cf8c58129eaae8b Reviewed-on: https://go-review.googlesource.com/c/go/+/342435 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
b0fba64ef4
commit
11a43df461
2 changed files with 14 additions and 10 deletions
|
|
@ -82,7 +82,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeName, targs []Type,
|
||||||
|
|
||||||
// Substitute type arguments for their respective type parameters in params,
|
// Substitute type arguments for their respective type parameters in params,
|
||||||
// if any. Note that nil targs entries are ignored by check.subst.
|
// if any. Note that nil targs entries are ignored by check.subst.
|
||||||
// TODO(gri) Can we avoid this (we're setting known type argumemts below,
|
// TODO(gri) Can we avoid this (we're setting known type arguments below,
|
||||||
// but that doesn't impact the isParameterized check for now).
|
// but that doesn't impact the isParameterized check for now).
|
||||||
if params.Len() > 0 {
|
if params.Len() > 0 {
|
||||||
smap := makeSubstMap(tparams, targs)
|
smap := makeSubstMap(tparams, targs)
|
||||||
|
|
|
||||||
|
|
@ -249,23 +249,27 @@ func writeTParamList(buf *bytes.Buffer, list []*TypeName, qf Qualifier, visited
|
||||||
buf.WriteString("[")
|
buf.WriteString("[")
|
||||||
var prev Type
|
var prev Type
|
||||||
for i, p := range list {
|
for i, p := range list {
|
||||||
// TODO(rFindley) support 'any' sugar here.
|
// Determine the type parameter and its constraint.
|
||||||
var b Type = &emptyInterface
|
// list is expected to hold type parameter names,
|
||||||
if t, _ := p.typ.(*TypeParam); t != nil && t.bound != nil {
|
// but don't crash if that's not the case.
|
||||||
b = t.bound
|
tpar, _ := p.typ.(*TypeParam)
|
||||||
|
var bound Type
|
||||||
|
if tpar != nil {
|
||||||
|
bound = tpar.bound // should not be nil but we want to see it if it is
|
||||||
}
|
}
|
||||||
|
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
if b != prev {
|
if bound != prev {
|
||||||
// type bound changed - write previous one before advancing
|
// bound changed - write previous one before advancing
|
||||||
buf.WriteByte(' ')
|
buf.WriteByte(' ')
|
||||||
writeType(buf, prev, qf, visited)
|
writeType(buf, prev, qf, visited)
|
||||||
}
|
}
|
||||||
buf.WriteString(", ")
|
buf.WriteString(", ")
|
||||||
}
|
}
|
||||||
prev = b
|
prev = bound
|
||||||
|
|
||||||
if t, _ := p.typ.(*TypeParam); t != nil {
|
if tpar != nil {
|
||||||
writeType(buf, t, qf, visited)
|
writeType(buf, tpar, qf, visited)
|
||||||
} else {
|
} else {
|
||||||
buf.WriteString(p.name)
|
buf.WriteString(p.name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue