cmd/compile/internal/syntax: record type parameters (don't just parse them)

Also: Distribute type parameter names if necessary.
Change-Id: I59d83c29548b62f21a65b225ee3e743c95287adc
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/744598
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2020-05-11 13:40:03 -07:00
parent 5f8feb36c0
commit 90f286c307
1 changed files with 16 additions and 1 deletions

View File

@ -666,7 +666,7 @@ func (p *parser) funcDeclOrNil() *FuncDecl {
tpos := p.pos()
p.want(_Lparen)
if p.got(_Type) {
p.paramList(true)
f.TParamList = p.paramList(true)
p.want(_Lparen)
}
f.Type = p.funcType(tpos, true)
@ -1669,6 +1669,21 @@ func (p *parser) paramList(tparams bool) (list []*Field) {
}
}
// TODO(gri) should do this when we distribute parameter types above
if tparams {
// determine which form we have (list of type parameters with optional
// contract, or type parameters, all with interfaces as type bounds)
for _, f := range list {
if f.Name == nil {
if debug && f.Type == nil {
panic("expected non-nil type")
}
f.Name = f.Type.(*Name)
f.Type = nil
}
}
}
return
}