Skip to content

Commit 12eb733

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 38c2e08 commit 12eb733

File tree

9 files changed

+47
-47
lines changed

9 files changed

+47
-47
lines changed

src/go/ast/ast.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,10 @@ type (
451451

452452
// A FuncType node represents a function type.
453453
FuncType struct {
454-
Func token.Pos // position of "func" keyword (token.NoPos if there is no "func")
455-
TParams *FieldList // type parameters; or nil
456-
Params *FieldList // (incoming) parameters; non-nil
457-
Results *FieldList // (outgoing) results; or nil
454+
Func token.Pos // position of "func" keyword (token.NoPos if there is no "func")
455+
TypeParams *FieldList // type parameters; or nil
456+
Params *FieldList // (incoming) parameters; non-nil
457+
Results *FieldList // (outgoing) results; or nil
458458
}
459459

460460
// An InterfaceType node represents an interface type.
@@ -915,12 +915,12 @@ type (
915915

916916
// A TypeSpec node represents a type declaration (TypeSpec production).
917917
TypeSpec struct {
918-
Doc *CommentGroup // associated documentation; or nil
919-
Name *Ident // type name
920-
TParams *FieldList // type parameters; or nil
921-
Assign token.Pos // position of '=', if any
922-
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
923-
Comment *CommentGroup // line comments; or nil
918+
Doc *CommentGroup // associated documentation; or nil
919+
Name *Ident // type name
920+
TypeParams *FieldList // type parameters; or nil
921+
Assign token.Pos // position of '=', if any
922+
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
923+
Comment *CommentGroup // line comments; or nil
924924
}
925925
)
926926

src/go/ast/walk.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ func Walk(v Visitor, node Node) {
169169
Walk(v, n.Fields)
170170

171171
case *FuncType:
172-
if n.TParams != nil {
173-
Walk(v, n.TParams)
172+
if n.TypeParams != nil {
173+
Walk(v, n.TypeParams)
174174
}
175175
if n.Params != nil {
176176
Walk(v, n.Params)
@@ -326,8 +326,8 @@ func Walk(v Visitor, node Node) {
326326
Walk(v, n.Doc)
327327
}
328328
Walk(v, n.Name)
329-
if n.TParams != nil {
330-
Walk(v, n.TParams)
329+
if n.TypeParams != nil {
330+
Walk(v, n.TypeParams)
331331
}
332332
Walk(v, n.Type)
333333
if n.Comment != nil {

src/go/parser/parser.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,10 @@ func (p *parser) parseMethodSpec() *ast.Field {
973973
results := p.parseResult()
974974
idents = []*ast.Ident{ident}
975975
typ = &ast.FuncType{
976-
Func: token.NoPos,
977-
TParams: tparams,
978-
Params: params,
979-
Results: results,
976+
Func: token.NoPos,
977+
TypeParams: tparams,
978+
Params: params,
979+
Results: results,
980980
}
981981
} else {
982982
// embedded instantiated type
@@ -2509,7 +2509,7 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, _ token.Pos, keyword toke
25092509
func (p *parser) parseGenericType(spec *ast.TypeSpec, openPos token.Pos, name0 *ast.Ident, closeTok token.Token) {
25102510
list := p.parseParameterList(name0, closeTok, p.parseParamDecl, true)
25112511
closePos := p.expect(closeTok)
2512-
spec.TParams = &ast.FieldList{Opening: openPos, List: list, Closing: closePos}
2512+
spec.TypeParams = &ast.FieldList{Opening: openPos, List: list, Closing: closePos}
25132513
// Type alias cannot have type parameters. Accept them for robustness but complain.
25142514
if p.tok == token.ASSIGN {
25152515
p.error(p.pos, "generic type cannot be alias")
@@ -2639,10 +2639,10 @@ func (p *parser) parseFuncDecl() *ast.FuncDecl {
26392639
Recv: recv,
26402640
Name: ident,
26412641
Type: &ast.FuncType{
2642-
Func: pos,
2643-
TParams: tparams,
2644-
Params: params,
2645-
Results: results,
2642+
Func: pos,
2643+
TypeParams: tparams,
2644+
Params: params,
2645+
Results: results,
26462646
},
26472647
Body: body,
26482648
}

src/go/parser/resolver.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,10 @@ func (r *resolver) Visit(node ast.Node) ast.Visitor {
454454
// at the identifier in the TypeSpec and ends at the end of the innermost
455455
// containing block.
456456
r.declare(spec, nil, r.topScope, ast.Typ, spec.Name)
457-
if spec.TParams != nil {
457+
if spec.TypeParams != nil {
458458
r.openScope(spec.Pos())
459459
defer r.closeScope()
460-
r.walkTParams(spec.TParams)
460+
r.walkTParams(spec.TypeParams)
461461
}
462462
ast.Walk(r, spec.Type)
463463
}
@@ -473,8 +473,8 @@ func (r *resolver) Visit(node ast.Node) ast.Visitor {
473473

474474
// Type parameters are walked normally: they can reference each other, and
475475
// can be referenced by normal parameters.
476-
if n.Type.TParams != nil {
477-
r.walkTParams(n.Type.TParams)
476+
if n.Type.TypeParams != nil {
477+
r.walkTParams(n.Type.TypeParams)
478478
// TODO(rFindley): need to address receiver type parameters.
479479
}
480480

@@ -499,7 +499,7 @@ func (r *resolver) Visit(node ast.Node) ast.Visitor {
499499
}
500500

501501
func (r *resolver) walkFuncType(typ *ast.FuncType) {
502-
// typ.TParams must be walked separately for FuncDecls.
502+
// typ.TypeParams must be walked separately for FuncDecls.
503503
r.resolveList(typ.Params)
504504
r.resolveList(typ.Results)
505505
r.declareList(typ.Params, ast.Var)

src/go/printer/nodes.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ func (p *printer) parameters(fields *ast.FieldList, isTypeParam bool) {
382382
}
383383

384384
func (p *printer) signature(sig *ast.FuncType) {
385-
if sig.TParams != nil {
386-
p.parameters(sig.TParams, true)
385+
if sig.TypeParams != nil {
386+
p.parameters(sig.TypeParams, true)
387387
}
388388
if sig.Params != nil {
389389
p.parameters(sig.Params, false)
@@ -1632,8 +1632,8 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) {
16321632
case *ast.TypeSpec:
16331633
p.setComment(s.Doc)
16341634
p.expr(s.Name)
1635-
if s.TParams != nil {
1636-
p.parameters(s.TParams, true)
1635+
if s.TypeParams != nil {
1636+
p.parameters(s.TypeParams, true)
16371637
}
16381638
if n == 1 {
16391639
p.print(blank)

src/go/types/decl.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *Named) {
589589
})
590590

591591
alias := tdecl.Assign.IsValid()
592-
if alias && tdecl.TParams.NumFields() != 0 {
592+
if alias && tdecl.TypeParams.NumFields() != 0 {
593593
// The parser will ensure this but we may still get an invalid AST.
594594
// Complain and continue as regular type definition.
595595
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) {
612612
named := check.newNamed(obj, nil, nil, nil, nil)
613613
def.setUnderlying(named)
614614

615-
if tdecl.TParams != nil {
615+
if tdecl.TypeParams != nil {
616616
check.openScope(tdecl, "type parameters")
617617
defer check.closeScope()
618-
named.tparams = check.collectTypeParams(tdecl.TParams)
618+
named.tparams = check.collectTypeParams(tdecl.TypeParams)
619619
}
620620

621621
// determine underlying type of named
@@ -791,7 +791,7 @@ func (check *Checker) funcDecl(obj *Func, decl *declInfo) {
791791
check.funcType(sig, fdecl.Recv, fdecl.Type)
792792
obj.color_ = saved
793793

794-
if fdecl.Type.TParams.NumFields() > 0 && fdecl.Body == nil {
794+
if fdecl.Type.TypeParams.NumFields() > 0 && fdecl.Body == nil {
795795
check.softErrorf(fdecl.Name, _Todo, "parameterized function is missing function body")
796796
}
797797

src/go/types/interface.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, d
194194
// a receiver specification.)
195195
if sig.tparams != nil {
196196
var at positioner = f.Type
197-
if ftyp, _ := f.Type.(*ast.FuncType); ftyp != nil && ftyp.TParams != nil {
198-
at = ftyp.TParams
197+
if ftyp, _ := f.Type.(*ast.FuncType); ftyp != nil && ftyp.TypeParams != nil {
198+
at = ftyp.TypeParams
199199
}
200200
check.errorf(at, _Todo, "methods cannot have type parameters")
201201
}

src/go/types/resolver.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ func (check *Checker) collectObjects() {
381381
check.declarePkgObj(name, obj, di)
382382
}
383383
case typeDecl:
384-
if d.spec.TParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) {
385-
check.softErrorf(d.spec.TParams.List[0], _Todo, "type parameters require go1.18 or later")
384+
if d.spec.TypeParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) {
385+
check.softErrorf(d.spec.TypeParams.List[0], _Todo, "type parameters require go1.18 or later")
386386
}
387387
obj := NewTypeName(d.spec.Name.Pos(), pkg, d.spec.Name.Name, nil)
388388
check.declarePkgObj(d.spec.Name, obj, &declInfo{file: fileScope, tdecl: d.spec})
@@ -401,8 +401,8 @@ func (check *Checker) collectObjects() {
401401
if name == "main" {
402402
code = _InvalidMainDecl
403403
}
404-
if d.decl.Type.TParams.NumFields() != 0 {
405-
check.softErrorf(d.decl.Type.TParams.List[0], code, "func %s must have no type parameters", name)
404+
if d.decl.Type.TypeParams.NumFields() != 0 {
405+
check.softErrorf(d.decl.Type.TypeParams.List[0], code, "func %s must have no type parameters", name)
406406
hasTParamError = true
407407
}
408408
if t := d.decl.Type; t.Params.NumFields() != 0 || t.Results != nil {
@@ -439,8 +439,8 @@ func (check *Checker) collectObjects() {
439439
}
440440
check.recordDef(d.decl.Name, obj)
441441
}
442-
if d.decl.Type.TParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) && !hasTParamError {
443-
check.softErrorf(d.decl.Type.TParams.List[0], _Todo, "type parameters require go1.18 or later")
442+
if d.decl.Type.TypeParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) && !hasTParamError {
443+
check.softErrorf(d.decl.Type.TypeParams.List[0], _Todo, "type parameters require go1.18 or later")
444444
}
445445
info := &declInfo{file: fileScope, fdecl: d.decl}
446446
// Methods are not package-level objects but we still track them in the

src/go/types/signature.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast
151151
}
152152
}
153153

154-
if ftyp.TParams != nil {
155-
sig.tparams = check.collectTypeParams(ftyp.TParams)
154+
if ftyp.TypeParams != nil {
155+
sig.tparams = check.collectTypeParams(ftyp.TypeParams)
156156
// Always type-check method type parameters but complain that they are not allowed.
157157
// (A separate check is needed when type-checking interface method signatures because
158158
// they don't have a receiver specification.)
159159
if recvPar != nil {
160-
check.errorf(ftyp.TParams, _Todo, "methods cannot have type parameters")
160+
check.errorf(ftyp.TypeParams, _Todo, "methods cannot have type parameters")
161161
}
162162
}
163163

0 commit comments

Comments
 (0)