]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/ast: rename TParams fields to TypeParams
authorRobert Findley <rfindley@google.com>
Wed, 8 Sep 2021 15:46:58 +0000 (11:46 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 8 Sep 2021 16:59:04 +0000 (16:59 +0000)
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>

src/go/ast/ast.go
src/go/ast/walk.go
src/go/parser/parser.go
src/go/parser/resolver.go
src/go/printer/nodes.go
src/go/types/decl.go
src/go/types/interface.go
src/go/types/resolver.go
src/go/types/signature.go

index b0f133056425652958430342ca433dce4b732656..f9223e4f91afa114383cb665c275198f501fea56 100644 (file)
@@ -451,10 +451,10 @@ type (
 
        // A FuncType node represents a function type.
        FuncType struct {
-               Func    token.Pos  // position of "func" keyword (token.NoPos if there is no "func")
-               TParams *FieldList // type parameters; or nil
-               Params  *FieldList // (incoming) parameters; non-nil
-               Results *FieldList // (outgoing) results; or nil
+               Func       token.Pos  // position of "func" keyword (token.NoPos if there is no "func")
+               TypeParams *FieldList // type parameters; or nil
+               Params     *FieldList // (incoming) parameters; non-nil
+               Results    *FieldList // (outgoing) results; or nil
        }
 
        // An InterfaceType node represents an interface type.
@@ -915,12 +915,12 @@ type (
 
        // A TypeSpec node represents a type declaration (TypeSpec production).
        TypeSpec struct {
-               Doc     *CommentGroup // associated documentation; or nil
-               Name    *Ident        // type name
-               TParams *FieldList    // type parameters; or nil
-               Assign  token.Pos     // position of '=', if any
-               Type    Expr          // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
-               Comment *CommentGroup // line comments; or nil
+               Doc        *CommentGroup // associated documentation; or nil
+               Name       *Ident        // type name
+               TypeParams *FieldList    // type parameters; or nil
+               Assign     token.Pos     // position of '=', if any
+               Type       Expr          // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
+               Comment    *CommentGroup // line comments; or nil
        }
 )
 
index c8abc40972842157dfaee016b5d669829ba51cf8..530735e76f068afe62e029c713e4602d9af7ab09 100644 (file)
@@ -169,8 +169,8 @@ func Walk(v Visitor, node Node) {
                Walk(v, n.Fields)
 
        case *FuncType:
-               if n.TParams != nil {
-                       Walk(v, n.TParams)
+               if n.TypeParams != nil {
+                       Walk(v, n.TypeParams)
                }
                if n.Params != nil {
                        Walk(v, n.Params)
@@ -326,8 +326,8 @@ func Walk(v Visitor, node Node) {
                        Walk(v, n.Doc)
                }
                Walk(v, n.Name)
-               if n.TParams != nil {
-                       Walk(v, n.TParams)
+               if n.TypeParams != nil {
+                       Walk(v, n.TypeParams)
                }
                Walk(v, n.Type)
                if n.Comment != nil {
index 5a7becf6da9c1a712a5df282b9a39a4c996497b3..5c0af8d3b835d4f7f86c77e4073b46939cd8855b 100644 (file)
@@ -973,10 +973,10 @@ func (p *parser) parseMethodSpec() *ast.Field {
                                results := p.parseResult()
                                idents = []*ast.Ident{ident}
                                typ = &ast.FuncType{
-                                       Func:    token.NoPos,
-                                       TParams: tparams,
-                                       Params:  params,
-                                       Results: results,
+                                       Func:       token.NoPos,
+                                       TypeParams: tparams,
+                                       Params:     params,
+                                       Results:    results,
                                }
                        } else {
                                // embedded instantiated type
@@ -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) {
        list := p.parseParameterList(name0, closeTok, p.parseParamDecl, true)
        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.
        if p.tok == token.ASSIGN {
                p.error(p.pos, "generic type cannot be alias")
@@ -2639,10 +2639,10 @@ func (p *parser) parseFuncDecl() *ast.FuncDecl {
                Recv: recv,
                Name: ident,
                Type: &ast.FuncType{
-                       Func:    pos,
-                       TParams: tparams,
-                       Params:  params,
-                       Results: results,
+                       Func:       pos,
+                       TypeParams: tparams,
+                       Params:     params,
+                       Results:    results,
                },
                Body: body,
        }
index cfdb5e1193c9866ac4502ed4f43a2ed8c2c06916..527f1691bda6fe295b4eded752e27873f7dee611 100644 (file)
@@ -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
                                // containing block.
                                r.declare(spec, nil, r.topScope, ast.Typ, spec.Name)
-                               if spec.TParams != nil {
+                               if spec.TypeParams != nil {
                                        r.openScope(spec.Pos())
                                        defer r.closeScope()
-                                       r.walkTParams(spec.TParams)
+                                       r.walkTParams(spec.TypeParams)
                                }
                                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
                // can be referenced by normal parameters.
-               if n.Type.TParams != nil {
-                       r.walkTParams(n.Type.TParams)
+               if n.Type.TypeParams != nil {
+                       r.walkTParams(n.Type.TypeParams)
                        // 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) {
-       // typ.TParams must be walked separately for FuncDecls.
+       // typ.TypeParams must be walked separately for FuncDecls.
        r.resolveList(typ.Params)
        r.resolveList(typ.Results)
        r.declareList(typ.Params, ast.Var)
index 58887153f21a4824973ada3bf97b2a9b5985da2d..9ce011542655db901b9fa88933504fe9e833a236 100644 (file)
@@ -382,8 +382,8 @@ func (p *printer) parameters(fields *ast.FieldList, isTypeParam bool) {
 }
 
 func (p *printer) signature(sig *ast.FuncType) {
-       if sig.TParams != nil {
-               p.parameters(sig.TParams, true)
+       if sig.TypeParams != nil {
+               p.parameters(sig.TypeParams, true)
        }
        if sig.Params != nil {
                p.parameters(sig.Params, false)
@@ -1632,8 +1632,8 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) {
        case *ast.TypeSpec:
                p.setComment(s.Doc)
                p.expr(s.Name)
-               if s.TParams != nil {
-                       p.parameters(s.TParams, true)
+               if s.TypeParams != nil {
+                       p.parameters(s.TypeParams, true)
                }
                if n == 1 {
                        p.print(blank)
index b48081f0b1d77a1c795655c3d6b3c936c93545ca..6dac807c75af586b0c042642858a5a87512cb839 100644 (file)
@@ -589,7 +589,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *Named) {
        })
 
        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.
                // Complain and continue as regular type definition.
                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)
        def.setUnderlying(named)
 
-       if tdecl.TParams != nil {
+       if tdecl.TypeParams != nil {
                check.openScope(tdecl, "type parameters")
                defer check.closeScope()
-               named.tparams = check.collectTypeParams(tdecl.TParams)
+               named.tparams = check.collectTypeParams(tdecl.TypeParams)
        }
 
        // determine underlying type of named
@@ -791,7 +791,7 @@ func (check *Checker) funcDecl(obj *Func, decl *declInfo) {
        check.funcType(sig, fdecl.Recv, fdecl.Type)
        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")
        }
 
index ebd246da984e6b5f361494529a01a8982bf0f665..2211e37c5981771a5adfdd7e10279003ab105962 100644 (file)
@@ -194,8 +194,8 @@ func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, d
                // a receiver specification.)
                if sig.tparams != nil {
                        var at positioner = f.Type
-                       if ftyp, _ := f.Type.(*ast.FuncType); ftyp != nil && ftyp.TParams != nil {
-                               at = ftyp.TParams
+                       if ftyp, _ := f.Type.(*ast.FuncType); ftyp != nil && ftyp.TypeParams != nil {
+                               at = ftyp.TypeParams
                        }
                        check.errorf(at, _Todo, "methods cannot have type parameters")
                }
index fb7e0cc47416b15a5ab27181ba381eaa758df9e9..b04a673ab7e98d8b7a5011e38503fb60fccd74c1 100644 (file)
@@ -381,8 +381,8 @@ func (check *Checker) collectObjects() {
                                        check.declarePkgObj(name, obj, di)
                                }
                        case typeDecl:
-                               if d.spec.TParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) {
-                                       check.softErrorf(d.spec.TParams.List[0], _Todo, "type parameters require go1.18 or later")
+                               if d.spec.TypeParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) {
+                                       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)
                                check.declarePkgObj(d.spec.Name, obj, &declInfo{file: fileScope, tdecl: d.spec})
@@ -401,8 +401,8 @@ func (check *Checker) collectObjects() {
                                                if name == "main" {
                                                        code = _InvalidMainDecl
                                                }
-                                               if d.decl.Type.TParams.NumFields() != 0 {
-                                                       check.softErrorf(d.decl.Type.TParams.List[0], code, "func %s must have no type parameters", name)
+                                               if d.decl.Type.TypeParams.NumFields() != 0 {
+                                                       check.softErrorf(d.decl.Type.TypeParams.List[0], code, "func %s must have no type parameters", name)
                                                        hasTParamError = true
                                                }
                                                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)
                                }
-                               if d.decl.Type.TParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) && !hasTParamError {
-                                       check.softErrorf(d.decl.Type.TParams.List[0], _Todo, "type parameters require go1.18 or later")
+                               if d.decl.Type.TypeParams.NumFields() != 0 && !check.allowVersion(pkg, 1, 18) && !hasTParamError {
+                                       check.softErrorf(d.decl.Type.TypeParams.List[0], _Todo, "type parameters require go1.18 or later")
                                }
                                info := &declInfo{file: fileScope, fdecl: d.decl}
                                // Methods are not package-level objects but we still track them in the
index 54e2e3e1eab1a42cc14ed37065f4357610ca4a72..6b3cf7270402a193e9c3fc6539c30f45ae6312c0 100644 (file)
@@ -151,13 +151,13 @@ func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast
                }
        }
 
-       if ftyp.TParams != nil {
-               sig.tparams = check.collectTypeParams(ftyp.TParams)
+       if ftyp.TypeParams != nil {
+               sig.tparams = check.collectTypeParams(ftyp.TypeParams)
                // 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
                // they don't have a receiver specification.)
                if recvPar != nil {
-                       check.errorf(ftyp.TParams, _Todo, "methods cannot have type parameters")
+                       check.errorf(ftyp.TypeParams, _Todo, "methods cannot have type parameters")
                }
        }