mirror of https://github.com/golang/go.git
go/ast: rename TParams fields to TypeParams
As discussed in the ast proposal (#47781), there's not really a strong reason to avoid spelling out 'Type'. Change-Id: I0ba1bf03b112ea60509a78a89a050a302779d9d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/348375 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
38c2e08cbd
commit
12eb7331b9
|
|
@ -452,7 +452,7 @@ type (
|
||||||
// A FuncType node represents a function type.
|
// A FuncType node represents a function type.
|
||||||
FuncType struct {
|
FuncType struct {
|
||||||
Func token.Pos // position of "func" keyword (token.NoPos if there is no "func")
|
Func token.Pos // position of "func" keyword (token.NoPos if there is no "func")
|
||||||
TParams *FieldList // type parameters; or nil
|
TypeParams *FieldList // type parameters; or nil
|
||||||
Params *FieldList // (incoming) parameters; non-nil
|
Params *FieldList // (incoming) parameters; non-nil
|
||||||
Results *FieldList // (outgoing) results; or nil
|
Results *FieldList // (outgoing) results; or nil
|
||||||
}
|
}
|
||||||
|
|
@ -917,7 +917,7 @@ type (
|
||||||
TypeSpec struct {
|
TypeSpec struct {
|
||||||
Doc *CommentGroup // associated documentation; or nil
|
Doc *CommentGroup // associated documentation; or nil
|
||||||
Name *Ident // type name
|
Name *Ident // type name
|
||||||
TParams *FieldList // type parameters; or nil
|
TypeParams *FieldList // type parameters; or nil
|
||||||
Assign token.Pos // position of '=', if any
|
Assign token.Pos // position of '=', if any
|
||||||
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
|
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
|
||||||
Comment *CommentGroup // line comments; or nil
|
Comment *CommentGroup // line comments; or nil
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,8 @@ func Walk(v Visitor, node Node) {
|
||||||
Walk(v, n.Fields)
|
Walk(v, n.Fields)
|
||||||
|
|
||||||
case *FuncType:
|
case *FuncType:
|
||||||
if n.TParams != nil {
|
if n.TypeParams != nil {
|
||||||
Walk(v, n.TParams)
|
Walk(v, n.TypeParams)
|
||||||
}
|
}
|
||||||
if n.Params != nil {
|
if n.Params != nil {
|
||||||
Walk(v, n.Params)
|
Walk(v, n.Params)
|
||||||
|
|
@ -326,8 +326,8 @@ func Walk(v Visitor, node Node) {
|
||||||
Walk(v, n.Doc)
|
Walk(v, n.Doc)
|
||||||
}
|
}
|
||||||
Walk(v, n.Name)
|
Walk(v, n.Name)
|
||||||
if n.TParams != nil {
|
if n.TypeParams != nil {
|
||||||
Walk(v, n.TParams)
|
Walk(v, n.TypeParams)
|
||||||
}
|
}
|
||||||
Walk(v, n.Type)
|
Walk(v, n.Type)
|
||||||
if n.Comment != nil {
|
if n.Comment != nil {
|
||||||
|
|
|
||||||
|
|
@ -974,7 +974,7 @@ func (p *parser) parseMethodSpec() *ast.Field {
|
||||||
idents = []*ast.Ident{ident}
|
idents = []*ast.Ident{ident}
|
||||||
typ = &ast.FuncType{
|
typ = &ast.FuncType{
|
||||||
Func: token.NoPos,
|
Func: token.NoPos,
|
||||||
TParams: tparams,
|
TypeParams: tparams,
|
||||||
Params: params,
|
Params: params,
|
||||||
Results: results,
|
Results: results,
|
||||||
}
|
}
|
||||||
|
|
@ -2509,7 +2509,7 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, _ token.Pos, keyword toke
|
||||||
func (p *parser) parseGenericType(spec *ast.TypeSpec, openPos token.Pos, name0 *ast.Ident, closeTok token.Token) {
|
func (p *parser) parseGenericType(spec *ast.TypeSpec, openPos token.Pos, name0 *ast.Ident, closeTok token.Token) {
|
||||||
list := p.parseParameterList(name0, closeTok, p.parseParamDecl, true)
|
list := p.parseParameterList(name0, closeTok, p.parseParamDecl, true)
|
||||||
closePos := p.expect(closeTok)
|
closePos := p.expect(closeTok)
|
||||||
spec.TParams = &ast.FieldList{Opening: openPos, List: list, Closing: closePos}
|
spec.TypeParams = &ast.FieldList{Opening: openPos, List: list, Closing: closePos}
|
||||||
// Type alias cannot have type parameters. Accept them for robustness but complain.
|
// Type alias cannot have type parameters. Accept them for robustness but complain.
|
||||||
if p.tok == token.ASSIGN {
|
if p.tok == token.ASSIGN {
|
||||||
p.error(p.pos, "generic type cannot be alias")
|
p.error(p.pos, "generic type cannot be alias")
|
||||||
|
|
@ -2640,7 +2640,7 @@ func (p *parser) parseFuncDecl() *ast.FuncDecl {
|
||||||
Name: ident,
|
Name: ident,
|
||||||
Type: &ast.FuncType{
|
Type: &ast.FuncType{
|
||||||
Func: pos,
|
Func: pos,
|
||||||
TParams: tparams,
|
TypeParams: tparams,
|
||||||
Params: params,
|
Params: params,
|
||||||
Results: results,
|
Results: results,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -454,10 +454,10 @@ func (r *resolver) Visit(node ast.Node) ast.Visitor {
|
||||||
// at the identifier in the TypeSpec and ends at the end of the innermost
|
// at the identifier in the TypeSpec and ends at the end of the innermost
|
||||||
// containing block.
|
// containing block.
|
||||||
r.declare(spec, nil, r.topScope, ast.Typ, spec.Name)
|
r.declare(spec, nil, r.topScope, ast.Typ, spec.Name)
|
||||||
if spec.TParams != nil {
|
if spec.TypeParams != nil {
|
||||||
r.openScope(spec.Pos())
|
r.openScope(spec.Pos())
|
||||||
defer r.closeScope()
|
defer r.closeScope()
|
||||||
r.walkTParams(spec.TParams)
|
r.walkTParams(spec.TypeParams)
|
||||||
}
|
}
|
||||||
ast.Walk(r, spec.Type)
|
ast.Walk(r, spec.Type)
|
||||||
}
|
}
|
||||||
|
|
@ -473,8 +473,8 @@ func (r *resolver) Visit(node ast.Node) ast.Visitor {
|
||||||
|
|
||||||
// Type parameters are walked normally: they can reference each other, and
|
// Type parameters are walked normally: they can reference each other, and
|
||||||
// can be referenced by normal parameters.
|
// can be referenced by normal parameters.
|
||||||
if n.Type.TParams != nil {
|
if n.Type.TypeParams != nil {
|
||||||
r.walkTParams(n.Type.TParams)
|
r.walkTParams(n.Type.TypeParams)
|
||||||
// TODO(rFindley): need to address receiver type parameters.
|
// TODO(rFindley): need to address receiver type parameters.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -499,7 +499,7 @@ func (r *resolver) Visit(node ast.Node) ast.Visitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *resolver) walkFuncType(typ *ast.FuncType) {
|
func (r *resolver) walkFuncType(typ *ast.FuncType) {
|
||||||
// typ.TParams must be walked separately for FuncDecls.
|
// typ.TypeParams must be walked separately for FuncDecls.
|
||||||
r.resolveList(typ.Params)
|
r.resolveList(typ.Params)
|
||||||
r.resolveList(typ.Results)
|
r.resolveList(typ.Results)
|
||||||
r.declareList(typ.Params, ast.Var)
|
r.declareList(typ.Params, ast.Var)
|
||||||
|
|
|
||||||
|
|
@ -382,8 +382,8 @@ func (p *printer) parameters(fields *ast.FieldList, isTypeParam bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *printer) signature(sig *ast.FuncType) {
|
func (p *printer) signature(sig *ast.FuncType) {
|
||||||
if sig.TParams != nil {
|
if sig.TypeParams != nil {
|
||||||
p.parameters(sig.TParams, true)
|
p.parameters(sig.TypeParams, true)
|
||||||
}
|
}
|
||||||
if sig.Params != nil {
|
if sig.Params != nil {
|
||||||
p.parameters(sig.Params, false)
|
p.parameters(sig.Params, false)
|
||||||
|
|
@ -1632,8 +1632,8 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) {
|
||||||
case *ast.TypeSpec:
|
case *ast.TypeSpec:
|
||||||
p.setComment(s.Doc)
|
p.setComment(s.Doc)
|
||||||
p.expr(s.Name)
|
p.expr(s.Name)
|
||||||
if s.TParams != nil {
|
if s.TypeParams != nil {
|
||||||
p.parameters(s.TParams, true)
|
p.parameters(s.TypeParams, true)
|
||||||
}
|
}
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
p.print(blank)
|
p.print(blank)
|
||||||
|
|
|
||||||
|
|
@ -589,7 +589,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *Named) {
|
||||||
})
|
})
|
||||||
|
|
||||||
alias := tdecl.Assign.IsValid()
|
alias := tdecl.Assign.IsValid()
|
||||||
if alias && tdecl.TParams.NumFields() != 0 {
|
if alias && tdecl.TypeParams.NumFields() != 0 {
|
||||||
// The parser will ensure this but we may still get an invalid AST.
|
// The parser will ensure this but we may still get an invalid AST.
|
||||||
// Complain and continue as regular type definition.
|
// Complain and continue as regular type definition.
|
||||||
check.error(atPos(tdecl.Assign), 0, "generic type cannot be alias")
|
check.error(atPos(tdecl.Assign), 0, "generic type cannot be alias")
|
||||||
|
|
@ -612,10 +612,10 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *Named) {
|
||||||
named := check.newNamed(obj, nil, nil, nil, nil)
|
named := check.newNamed(obj, nil, nil, nil, nil)
|
||||||
def.setUnderlying(named)
|
def.setUnderlying(named)
|
||||||
|
|
||||||
if tdecl.TParams != nil {
|
if tdecl.TypeParams != nil {
|
||||||
check.openScope(tdecl, "type parameters")
|
check.openScope(tdecl, "type parameters")
|
||||||
defer check.closeScope()
|
defer check.closeScope()
|
||||||
named.tparams = check.collectTypeParams(tdecl.TParams)
|
named.tparams = check.collectTypeParams(tdecl.TypeParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine underlying type of named
|
// determine underlying type of named
|
||||||
|
|
@ -791,7 +791,7 @@ func (check *Checker) funcDecl(obj *Func, decl *declInfo) {
|
||||||
check.funcType(sig, fdecl.Recv, fdecl.Type)
|
check.funcType(sig, fdecl.Recv, fdecl.Type)
|
||||||
obj.color_ = saved
|
obj.color_ = saved
|
||||||
|
|
||||||
if fdecl.Type.TParams.NumFields() > 0 && fdecl.Body == nil {
|
if fdecl.Type.TypeParams.NumFields() > 0 && fdecl.Body == nil {
|
||||||
check.softErrorf(fdecl.Name, _Todo, "parameterized function is missing function body")
|
check.softErrorf(fdecl.Name, _Todo, "parameterized function is missing function body")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,8 +194,8 @@ func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, d
|
||||||
// a receiver specification.)
|
// a receiver specification.)
|
||||||
if sig.tparams != nil {
|
if sig.tparams != nil {
|
||||||
var at positioner = f.Type
|
var at positioner = f.Type
|
||||||
if ftyp, _ := f.Type.(*ast.FuncType); ftyp != nil && ftyp.TParams != nil {
|
if ftyp, _ := f.Type.(*ast.FuncType); ftyp != nil && ftyp.TypeParams != nil {
|
||||||
at = ftyp.TParams
|
at = ftyp.TypeParams
|
||||||
}
|
}
|
||||||
check.errorf(at, _Todo, "methods cannot have type parameters")
|
check.errorf(at, _Todo, "methods cannot have type parameters")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -381,8 +381,8 @@ func (check *Checker) collectObjects() {
|
||||||
check.declarePkgObj(name, obj, di)
|
check.declarePkgObj(name, obj, di)
|
||||||
}
|
}
|
||||||
case typeDecl:
|
case typeDecl:
|
||||||
if d.spec.TParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) {
|
if d.spec.TypeParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) {
|
||||||
check.softErrorf(d.spec.TParams.List[0], _Todo, "type parameters require go1.18 or later")
|
check.softErrorf(d.spec.TypeParams.List[0], _Todo, "type parameters require go1.18 or later")
|
||||||
}
|
}
|
||||||
obj := NewTypeName(d.spec.Name.Pos(), pkg, d.spec.Name.Name, nil)
|
obj := NewTypeName(d.spec.Name.Pos(), pkg, d.spec.Name.Name, nil)
|
||||||
check.declarePkgObj(d.spec.Name, obj, &declInfo{file: fileScope, tdecl: d.spec})
|
check.declarePkgObj(d.spec.Name, obj, &declInfo{file: fileScope, tdecl: d.spec})
|
||||||
|
|
@ -401,8 +401,8 @@ func (check *Checker) collectObjects() {
|
||||||
if name == "main" {
|
if name == "main" {
|
||||||
code = _InvalidMainDecl
|
code = _InvalidMainDecl
|
||||||
}
|
}
|
||||||
if d.decl.Type.TParams.NumFields() != 0 {
|
if d.decl.Type.TypeParams.NumFields() != 0 {
|
||||||
check.softErrorf(d.decl.Type.TParams.List[0], code, "func %s must have no type parameters", name)
|
check.softErrorf(d.decl.Type.TypeParams.List[0], code, "func %s must have no type parameters", name)
|
||||||
hasTParamError = true
|
hasTParamError = true
|
||||||
}
|
}
|
||||||
if t := d.decl.Type; t.Params.NumFields() != 0 || t.Results != nil {
|
if t := d.decl.Type; t.Params.NumFields() != 0 || t.Results != nil {
|
||||||
|
|
@ -439,8 +439,8 @@ func (check *Checker) collectObjects() {
|
||||||
}
|
}
|
||||||
check.recordDef(d.decl.Name, obj)
|
check.recordDef(d.decl.Name, obj)
|
||||||
}
|
}
|
||||||
if d.decl.Type.TParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) && !hasTParamError {
|
if d.decl.Type.TypeParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) && !hasTParamError {
|
||||||
check.softErrorf(d.decl.Type.TParams.List[0], _Todo, "type parameters require go1.18 or later")
|
check.softErrorf(d.decl.Type.TypeParams.List[0], _Todo, "type parameters require go1.18 or later")
|
||||||
}
|
}
|
||||||
info := &declInfo{file: fileScope, fdecl: d.decl}
|
info := &declInfo{file: fileScope, fdecl: d.decl}
|
||||||
// Methods are not package-level objects but we still track them in the
|
// Methods are not package-level objects but we still track them in the
|
||||||
|
|
|
||||||
|
|
@ -151,13 +151,13 @@ func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ftyp.TParams != nil {
|
if ftyp.TypeParams != nil {
|
||||||
sig.tparams = check.collectTypeParams(ftyp.TParams)
|
sig.tparams = check.collectTypeParams(ftyp.TypeParams)
|
||||||
// Always type-check method type parameters but complain that they are not allowed.
|
// Always type-check method type parameters but complain that they are not allowed.
|
||||||
// (A separate check is needed when type-checking interface method signatures because
|
// (A separate check is needed when type-checking interface method signatures because
|
||||||
// they don't have a receiver specification.)
|
// they don't have a receiver specification.)
|
||||||
if recvPar != nil {
|
if recvPar != nil {
|
||||||
check.errorf(ftyp.TParams, _Todo, "methods cannot have type parameters")
|
check.errorf(ftyp.TypeParams, _Todo, "methods cannot have type parameters")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue