From 79a80ff021ae0ec939d0c32026332f850aa41653 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Oct 2021 17:01:39 +0000 Subject: [PATCH] Bump golang.org/x/tools from 0.1.6 to 0.1.7 Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.1.6 to 0.1.7. - [Release notes](https://github.com/golang/tools/releases) - [Commits](https://github.com/golang/tools/compare/v0.1.6...v0.1.7) --- updated-dependencies: - dependency-name: golang.org/x/tools dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../x/tools/go/internal/gcimporter/bexport.go | 20 +- .../x/tools/go/internal/gcimporter/iexport.go | 198 +++++++++++++++--- .../x/tools/go/internal/gcimporter/iimport.go | 32 +-- .../go/internal/gcimporter/support_go117.go | 6 +- .../go/internal/gcimporter/support_go118.go | 6 +- .../internal/typeparams/enabled_go117.go | 4 +- .../internal/typeparams/enabled_go118.go | 4 +- .../internal/typeparams/typeparams_go117.go | 45 ++-- .../internal/typeparams/typeparams_go118.go | 73 +++---- .../x/tools/internal/typesinternal/types.go | 9 +- vendor/modules.txt | 2 +- 13 files changed, 277 insertions(+), 128 deletions(-) diff --git a/go.mod b/go.mod index 766748272c..211ad9311e 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect - golang.org/x/tools v0.1.6 + golang.org/x/tools v0.1.7 google.golang.org/genproto v0.0.0-20211005153810-c76a74d43a8e // indirect google.golang.org/grpc v1.41.0 // indirect gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect diff --git a/go.sum b/go.sum index 2bd773c25b..06a1d79e52 100644 --- a/go.sum +++ b/go.sum @@ -1120,8 +1120,8 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.6 h1:SIasE1FVIQOWz2GEAHFOmoW7xchJcqlucjSULTL0Ag4= -golang.org/x/tools v0.1.6/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= +golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ= +golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/bexport.go b/vendor/golang.org/x/tools/go/internal/gcimporter/bexport.go index a807d0aaa2..072005af89 100644 --- a/vendor/golang.org/x/tools/go/internal/gcimporter/bexport.go +++ b/vendor/golang.org/x/tools/go/internal/gcimporter/bexport.go @@ -92,16 +92,18 @@ func internalErrorf(format string, args ...interface{}) error { // BExportData returns binary export data for pkg. // If no file set is provided, position info will be missing. func BExportData(fset *token.FileSet, pkg *types.Package) (b []byte, err error) { - defer func() { - if e := recover(); e != nil { - if ierr, ok := e.(internalError); ok { - err = ierr - return + if !debug { + defer func() { + if e := recover(); e != nil { + if ierr, ok := e.(internalError); ok { + err = ierr + return + } + // Not an internal error; panic again. + panic(e) } - // Not an internal error; panic again. - panic(e) - } - }() + }() + } p := exporter{ fset: fset, diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/iexport.go b/vendor/golang.org/x/tools/go/internal/gcimporter/iexport.go index d2fc8b6fa3..be8b7459af 100644 --- a/vendor/golang.org/x/tools/go/internal/gcimporter/iexport.go +++ b/vendor/golang.org/x/tools/go/internal/gcimporter/iexport.go @@ -19,11 +19,9 @@ import ( "math/big" "reflect" "sort" -) -// Current indexed export format version. Increase with each format change. -// 0: Go1.11 encoding -const iexportVersion = 0 + "golang.org/x/tools/internal/typeparams" +) // Current bundled export format version. Increase with each format change. // 0: initial implementation @@ -44,16 +42,18 @@ func IExportBundle(out io.Writer, fset *token.FileSet, pkgs []*types.Package) er } func iexportCommon(out io.Writer, fset *token.FileSet, bundle bool, pkgs []*types.Package) (err error) { - defer func() { - if e := recover(); e != nil { - if ierr, ok := e.(internalError); ok { - err = ierr - return + if !debug { + defer func() { + if e := recover(); e != nil { + if ierr, ok := e.(internalError); ok { + err = ierr + return + } + // Not an internal error; panic again. + panic(e) } - // Not an internal error; panic again. - panic(e) - } - }() + }() + } p := iexporter{ fset: fset, @@ -158,7 +158,7 @@ func (w *exportWriter) writeIndex(index map[types.Object]uint64) { pkgs = append(pkgs, pkg) sort.Slice(objs, func(i, j int) bool { - return objs[i].Name() < objs[j].Name() + return indexName(objs[i]) < indexName(objs[j]) }) } @@ -175,12 +175,26 @@ func (w *exportWriter) writeIndex(index map[types.Object]uint64) { objs := pkgObjs[pkg] w.uint64(uint64(len(objs))) for _, obj := range objs { - w.string(obj.Name()) + w.string(indexName(obj)) w.uint64(index[obj]) } } } +// indexName returns the 'indexed' name of an object. It differs from +// obj.Name() only for type parameter names, where we include the subscripted +// type parameter ID. +// +// TODO(rfindley): remove this once we no longer need subscripts. +func indexName(obj types.Object) (res string) { + if _, ok := obj.(*types.TypeName); ok { + if tparam, ok := obj.Type().(*typeparams.TypeParam); ok { + return types.TypeString(tparam, func(*types.Package) string { return "" }) + } + } + return obj.Name() +} + type iexporter struct { fset *token.FileSet out *bytes.Buffer @@ -233,10 +247,11 @@ func (p *iexporter) pushDecl(obj types.Object) { type exportWriter struct { p *iexporter - data intWriter - currPkg *types.Package - prevFile string - prevLine int64 + data intWriter + currPkg *types.Package + prevFile string + prevLine int64 + prevColumn int64 } func (w *exportWriter) exportPath(pkg *types.Package) string { @@ -261,8 +276,23 @@ func (p *iexporter) doDecl(obj types.Object) { if sig.Recv() != nil { panic(internalErrorf("unexpected method: %v", sig)) } - w.tag('F') + + // Function. + if typeparams.ForSignature(sig).Len() == 0 { + w.tag('F') + } else { + w.tag('G') + } w.pos(obj.Pos()) + // The tparam list of the function type is the + // declaration of the type params. So, write out the type + // params right now. Then those type params will be + // referenced via their type offset (via typOff) in all + // other places in the signature and function that they + // are used. + if tparams := typeparams.ForSignature(sig); tparams.Len() > 0 { + w.tparamList(tparams, obj.Pkg()) + } w.signature(sig) case *types.Const: @@ -271,30 +301,46 @@ func (p *iexporter) doDecl(obj types.Object) { w.value(obj.Type(), obj.Val()) case *types.TypeName: + t := obj.Type() + + if tparam, ok := t.(*typeparams.TypeParam); ok { + w.tag('P') + w.pos(obj.Pos()) + w.typ(tparam.Constraint(), obj.Pkg()) + break + } + if obj.IsAlias() { w.tag('A') w.pos(obj.Pos()) - w.typ(obj.Type(), obj.Pkg()) + w.typ(t, obj.Pkg()) break } // Defined type. - w.tag('T') + named, ok := t.(*types.Named) + if !ok { + panic(internalErrorf("%s is not a defined type", t)) + } + + if typeparams.ForNamed(named).Len() == 0 { + w.tag('T') + } else { + w.tag('U') + } w.pos(obj.Pos()) + if typeparams.ForNamed(named).Len() > 0 { + w.tparamList(typeparams.ForNamed(named), obj.Pkg()) + } + underlying := obj.Type().Underlying() w.typ(underlying, obj.Pkg()) - t := obj.Type() if types.IsInterface(t) { break } - named, ok := t.(*types.Named) - if !ok { - panic(internalErrorf("%s is not a defined type", t)) - } - n := named.NumMethods() w.uint64(uint64(n)) for i := 0; i < n; i++ { @@ -318,6 +364,48 @@ func (w *exportWriter) tag(tag byte) { } func (w *exportWriter) pos(pos token.Pos) { + if iexportVersion >= iexportVersionPosCol { + w.posV1(pos) + } else { + w.posV0(pos) + } +} + +func (w *exportWriter) posV1(pos token.Pos) { + if w.p.fset == nil { + w.int64(0) + return + } + + p := w.p.fset.Position(pos) + file := p.Filename + line := int64(p.Line) + column := int64(p.Column) + + deltaColumn := (column - w.prevColumn) << 1 + deltaLine := (line - w.prevLine) << 1 + + if file != w.prevFile { + deltaLine |= 1 + } + if deltaLine != 0 { + deltaColumn |= 1 + } + + w.int64(deltaColumn) + if deltaColumn&1 != 0 { + w.int64(deltaLine) + if deltaLine&1 != 0 { + w.string(file) + } + } + + w.prevFile = file + w.prevLine = line + w.prevColumn = column +} + +func (w *exportWriter) posV0(pos token.Pos) { if w.p.fset == nil { w.int64(0) return @@ -361,8 +449,7 @@ func (w *exportWriter) pkg(pkg *types.Package) { func (w *exportWriter) qualifiedIdent(obj types.Object) { // Ensure any referenced declarations are written out too. w.p.pushDecl(obj) - - w.string(obj.Name()) + w.string(indexName(obj)) w.pkg(obj.Pkg()) } @@ -398,9 +485,22 @@ func (w *exportWriter) startType(k itag) { func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) { switch t := t.(type) { case *types.Named: + if targs := typeparams.NamedTypeArgs(t); targs.Len() > 0 { + w.startType(instanceType) + // TODO(rfindley): investigate if this position is correct, and if it + // matters. + w.pos(t.Obj().Pos()) + w.typeList(targs, pkg) + w.typ(typeparams.NamedTypeOrigin(t), pkg) + return + } w.startType(definedType) w.qualifiedIdent(t.Obj()) + case *typeparams.TypeParam: + w.startType(typeParamType) + w.qualifiedIdent(t.Obj()) + case *types.Pointer: w.startType(pointerType) w.typ(t.Elem(), pkg) @@ -461,9 +561,14 @@ func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) { n := t.NumEmbeddeds() w.uint64(uint64(n)) for i := 0; i < n; i++ { - f := t.Embedded(i) - w.pos(f.Obj().Pos()) - w.typ(f.Obj().Type(), f.Obj().Pkg()) + ft := t.EmbeddedType(i) + tPkg := pkg + if named, _ := ft.(*types.Named); named != nil { + w.pos(named.Obj().Pos()) + } else { + w.pos(token.NoPos) + } + w.typ(ft, tPkg) } n = t.NumExplicitMethods() @@ -476,6 +581,16 @@ func (w *exportWriter) doTyp(t types.Type, pkg *types.Package) { w.signature(sig) } + case *typeparams.Union: + w.startType(unionType) + nt := t.Len() + w.uint64(uint64(nt)) + for i := 0; i < nt; i++ { + term := t.Term(i) + w.bool(term.Tilde()) + w.typ(term.Type(), pkg) + } + default: panic(internalErrorf("unexpected type: %v, %v", t, reflect.TypeOf(t))) } @@ -497,6 +612,21 @@ func (w *exportWriter) signature(sig *types.Signature) { } } +func (w *exportWriter) typeList(ts *typeparams.TypeList, pkg *types.Package) { + w.uint64(uint64(ts.Len())) + for i := 0; i < ts.Len(); i++ { + w.typ(ts.At(i), pkg) + } +} + +func (w *exportWriter) tparamList(list *typeparams.TypeParamList, pkg *types.Package) { + ll := uint64(list.Len()) + w.uint64(ll) + for i := 0; i < list.Len(); i++ { + w.typ(list.At(i), pkg) + } +} + func (w *exportWriter) paramList(tup *types.Tuple) { n := tup.Len() w.uint64(uint64(n)) @@ -702,7 +832,7 @@ func (w *exportWriter) localIdent(obj types.Object) { return } - name := obj.Name() + name := indexName(obj) if name == "_" { w.string("_") return diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/iimport.go b/vendor/golang.org/x/tools/go/internal/gcimporter/iimport.go index 6f166d7f5a..1fcc87e58e 100644 --- a/vendor/golang.org/x/tools/go/internal/gcimporter/iimport.go +++ b/vendor/golang.org/x/tools/go/internal/gcimporter/iimport.go @@ -98,15 +98,17 @@ func IImportBundle(fset *token.FileSet, imports map[string]*types.Package, data func iimportCommon(fset *token.FileSet, imports map[string]*types.Package, data []byte, bundle bool, path string) (pkgs []*types.Package, err error) { const currentVersion = 1 version := int64(-1) - defer func() { - if e := recover(); e != nil { - if version > currentVersion { - err = fmt.Errorf("cannot import %q (%v), export data is newer version - update tool", path, e) - } else { - err = fmt.Errorf("cannot import %q (%v), possibly version skew - reinstall package", path, e) + if !debug { + defer func() { + if e := recover(); e != nil { + if version > currentVersion { + err = fmt.Errorf("cannot import %q (%v), export data is newer version - update tool", path, e) + } else { + err = fmt.Errorf("cannot import %q (%v), possibly version skew - reinstall package", path, e) + } } - } - }() + }() + } r := &intReader{bytes.NewReader(data), path} @@ -381,10 +383,14 @@ func (r *importReader) obj(name string) { // rparams of the method (since those are the // typeparams being used in the method sig/body). targs := typeparams.NamedTypeArgs(baseType(msig.Recv().Type())) - if len(targs) > 0 { - rparams := make([]*typeparams.TypeParam, len(targs)) + if targs.Len() > 0 { + rparams := make([]*typeparams.TypeParam, targs.Len()) for i := range rparams { - rparams[i], _ = targs[i].(*typeparams.TypeParam) + // TODO(rfindley): this is less tolerant than the standard library + // go/internal/gcimporter, which calls under(...) and is tolerant + // of nil rparams. Bring them in sync by making the standard + // library importer stricter. + rparams[i] = targs.At(i).(*typeparams.TypeParam) } typeparams.SetRecvTypeParams(msig, rparams) } @@ -404,7 +410,7 @@ func (r *importReader) obj(name string) { tn := types.NewTypeName(pos, r.currPkg, name0, nil) t := typeparams.NewTypeParam(tn, nil) if sub == 0 { - errorf("missing subscript") + errorf("name %q missing subscript", name) } // TODO(rfindley): can we use a different, stable ID? @@ -575,7 +581,7 @@ func (r *importReader) qualifiedIdent() (*types.Package, string) { } func (r *importReader) pos() token.Pos { - if r.p.version >= 1 { + if r.p.exportVersion >= iexportVersionPosCol { r.posv1() } else { r.posv0() diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/support_go117.go b/vendor/golang.org/x/tools/go/internal/gcimporter/support_go117.go index e6403e18a9..817a147ef0 100644 --- a/vendor/golang.org/x/tools/go/internal/gcimporter/support_go117.go +++ b/vendor/golang.org/x/tools/go/internal/gcimporter/support_go117.go @@ -2,13 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !go1.18 -// +build !go1.18 +//go:build !typeparams || !go1.18 +// +build !typeparams !go1.18 package gcimporter import "go/types" +const iexportVersion = iexportVersionGo1_11 + func additionalPredeclared() []types.Type { return nil } diff --git a/vendor/golang.org/x/tools/go/internal/gcimporter/support_go118.go b/vendor/golang.org/x/tools/go/internal/gcimporter/support_go118.go index a5c74856a7..e6b81fc50e 100644 --- a/vendor/golang.org/x/tools/go/internal/gcimporter/support_go118.go +++ b/vendor/golang.org/x/tools/go/internal/gcimporter/support_go118.go @@ -2,13 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.18 -// +build go1.18 +//go:build typeparams && go1.18 +// +build typeparams,go1.18 package gcimporter import "go/types" +const iexportVersion = iexportVersionGenerics + // additionalPredeclared returns additional predeclared types in go.1.18. func additionalPredeclared() []types.Type { return []types.Type{ diff --git a/vendor/golang.org/x/tools/internal/typeparams/enabled_go117.go b/vendor/golang.org/x/tools/internal/typeparams/enabled_go117.go index 18212390e1..72d010e518 100644 --- a/vendor/golang.org/x/tools/internal/typeparams/enabled_go117.go +++ b/vendor/golang.org/x/tools/internal/typeparams/enabled_go117.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !go1.18 -// +build !go1.18 +//go:build !typeparams || !go1.18 +// +build !typeparams !go1.18 package typeparams diff --git a/vendor/golang.org/x/tools/internal/typeparams/enabled_go118.go b/vendor/golang.org/x/tools/internal/typeparams/enabled_go118.go index d67148823c..642fc8ee21 100644 --- a/vendor/golang.org/x/tools/internal/typeparams/enabled_go118.go +++ b/vendor/golang.org/x/tools/internal/typeparams/enabled_go118.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.18 -// +build go1.18 +//go:build typeparams && go1.18 +// +build typeparams,go1.18 package typeparams diff --git a/vendor/golang.org/x/tools/internal/typeparams/typeparams_go117.go b/vendor/golang.org/x/tools/internal/typeparams/typeparams_go117.go index d015ee1afa..12817af856 100644 --- a/vendor/golang.org/x/tools/internal/typeparams/typeparams_go117.go +++ b/vendor/golang.org/x/tools/internal/typeparams/typeparams_go117.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !go1.18 -// +build !go1.18 +//go:build !typeparams || !go1.18 +// +build !typeparams !go1.18 package typeparams @@ -30,15 +30,15 @@ func GetIndexExprData(n ast.Node) *IndexExprData { return nil } -// ForTypeDecl returns an empty field list, as type parameters on not supported +// ForTypeSpec returns an empty field list, as type parameters on not supported // at this Go version. -func ForTypeDecl(*ast.TypeSpec) *ast.FieldList { +func ForTypeSpec(*ast.TypeSpec) *ast.FieldList { return nil } -// ForFuncDecl returns an empty field list, as type parameters are not +// ForFuncType returns an empty field list, as type parameters are not // supported at this Go version. -func ForFuncDecl(*ast.FuncDecl) *ast.FieldList { +func ForFuncType(*ast.FuncType) *ast.FieldList { return nil } @@ -46,6 +46,9 @@ func ForFuncDecl(*ast.FuncDecl) *ast.FieldList { // this Go version. Its methods panic on use. type TypeParam struct{ types.Type } +func (*TypeParam) Constraint() types.Type { unsupported(); return nil } +func (*TypeParam) Obj() *types.TypeName { unsupported(); return nil } + // TypeParamList is a placeholder for an empty type parameter list. type TypeParamList struct{} @@ -118,14 +121,24 @@ func SetForNamed(_ *types.Named, tparams []*TypeParam) { } } -// NamedTypeArgs extracts the (possibly empty) type argument list from named. -func NamedTypeArgs(*types.Named) []types.Type { +// NamedTypeArgs returns nil. +func NamedTypeArgs(*types.Named) *TypeList { return nil } +// NamedTypeOrigin is the identity method at this Go version. +func NamedTypeOrigin(named *types.Named) types.Type { + return named +} + // Term is a placeholder type, as type parameters are not supported at this Go // version. Its methods panic on use. -type Term struct{ types.Type } +type Term struct{} + +func (*Term) Tilde() bool { unsupported(); return false } +func (*Term) Type() types.Type { unsupported(); return nil } +func (*Term) String() string { unsupported(); return "" } +func (*Term) Underlying() types.Type { unsupported(); return nil } // NewTerm is unsupported at this Go version, and panics. func NewTerm(tilde bool, typ types.Type) *Term { @@ -137,21 +150,21 @@ func NewTerm(tilde bool, typ types.Type) *Term { // version. Its methods panic on use. type Union struct{ types.Type } +func (*Union) Len() int { return 0 } +func (*Union) Term(i int) *Term { unsupported(); return nil } + // NewUnion is unsupported at this Go version, and panics. func NewUnion(terms []*Term) *Union { unsupported() return nil } -// InitInferred is a noop at this Go version. -func InitInferred(*types.Info) { -} +// InitInstanceInfo is a noop at this Go version. +func InitInstanceInfo(*types.Info) {} -// GetInferred returns nothing, as type parameters are not supported at this Go +// GetInstance returns nothing, as type parameters are not supported at this Go // version. -func GetInferred(*types.Info, ast.Expr) ([]types.Type, *types.Signature) { - return nil, nil -} +func GetInstance(*types.Info, *ast.Ident) (*TypeList, types.Type) { return nil, nil } // Environment is a placeholder type, as type parameters are not supported at // this Go version. diff --git a/vendor/golang.org/x/tools/internal/typeparams/typeparams_go118.go b/vendor/golang.org/x/tools/internal/typeparams/typeparams_go118.go index 3e808e774d..8ab17b7779 100644 --- a/vendor/golang.org/x/tools/internal/typeparams/typeparams_go118.go +++ b/vendor/golang.org/x/tools/internal/typeparams/typeparams_go118.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.18 -// +build go1.18 +//go:build typeparams && go1.18 +// +build typeparams,go1.18 package typeparams @@ -36,17 +36,20 @@ func GetIndexExprData(n ast.Node) *IndexExprData { return nil } -// ForTypeDecl returns n.TypeParams. -func ForTypeDecl(n *ast.TypeSpec) *ast.FieldList { +// ForTypeSpec returns n.TypeParams. +func ForTypeSpec(n *ast.TypeSpec) *ast.FieldList { + if n == nil { + return nil + } return n.TypeParams } -// ForFuncDecl returns n.Type.TypeParams. -func ForFuncDecl(n *ast.FuncDecl) *ast.FieldList { - if n.Type != nil { - return n.Type.TypeParams +// ForFuncType returns n.TypeParams. +func ForFuncType(n *ast.FuncType) *ast.FieldList { + if n == nil { + return nil } - return nil + return n.TypeParams } // TypeParam is an alias for types.TypeParam @@ -110,17 +113,14 @@ func SetForNamed(n *types.Named, tparams []*TypeParam) { n.SetTypeParams(tparams) } -// NamedTypeArgs extracts the (possibly empty) type argument list from named. -func NamedTypeArgs(named *types.Named) []types.Type { - targs := named.TypeArgs() - numArgs := targs.Len() - - typs := make([]types.Type, numArgs) - for i := 0; i < numArgs; i++ { - typs[i] = targs.At(i) - } +// NamedTypeArgs returns named.TypeArgs(). +func NamedTypeArgs(named *types.Named) *TypeList { + return named.TypeArgs() +} - return typs +// NamedTypeOrigin returns named.Orig(). +func NamedTypeOrigin(named *types.Named) types.Type { + return named.Origin() } // Term is an alias for types.Term. @@ -139,32 +139,21 @@ func NewUnion(terms []*Term) *Union { return types.NewUnion(terms) } -// InitInferred initializes info to record inferred type information. -func InitInferred(info *types.Info) { - info.Inferred = make(map[ast.Expr]types.Inferred) +// InitInstanceInfo initializes info to record information about type and +// function instances. +func InitInstanceInfo(info *types.Info) { + info.Instances = make(map[*ast.Ident]types.Instance) } -// GetInferred extracts inferred type information from info for e. -// -// The expression e may have an inferred type if it is an *ast.IndexExpr -// representing partial instantiation of a generic function type for which type -// arguments have been inferred using constraint type inference, or if it is an -// *ast.CallExpr for which type type arguments have be inferred using both -// constraint type inference and function argument inference. -func GetInferred(info *types.Info, e ast.Expr) ([]types.Type, *types.Signature) { - if info.Inferred == nil { - return nil, nil +// GetInstance extracts information about the instantiation occurring at the +// identifier id. id should be the identifier denoting a parameterized type or +// function in an instantiation expression or function call. +func GetInstance(info *types.Info, id *ast.Ident) (*TypeList, types.Type) { + if info.Instances != nil { + inf := info.Instances[id] + return inf.TypeArgs, inf.Type } - inf := info.Inferred[e] - - length := inf.TArgs.Len() - - typs := make([]types.Type, length) - for i := 0; i < length; i++ { - typs[i] = inf.TArgs.At(i) - } - - return typs, inf.Sig + return nil, nil } // Environment is an alias for types.Environment. diff --git a/vendor/golang.org/x/tools/internal/typesinternal/types.go b/vendor/golang.org/x/tools/internal/typesinternal/types.go index c3e1a397db..7c77c2fbc0 100644 --- a/vendor/golang.org/x/tools/internal/typesinternal/types.go +++ b/vendor/golang.org/x/tools/internal/typesinternal/types.go @@ -30,10 +30,15 @@ func SetUsesCgo(conf *types.Config) bool { return true } -func ReadGo116ErrorData(terr types.Error) (ErrorCode, token.Pos, token.Pos, bool) { +// ReadGo116ErrorData extracts additional information from types.Error values +// generated by Go version 1.16 and later: the error code, start position, and +// end position. If all positions are valid, start <= err.Pos <= end. +// +// If the data could not be read, the final result parameter will be false. +func ReadGo116ErrorData(err types.Error) (code ErrorCode, start, end token.Pos, ok bool) { var data [3]int // By coincidence all of these fields are ints, which simplifies things. - v := reflect.ValueOf(terr) + v := reflect.ValueOf(err) for i, name := range []string{"go116code", "go116start", "go116end"} { f := v.FieldByName(name) if !f.IsValid() { diff --git a/vendor/modules.txt b/vendor/modules.txt index e44bc6bc4e..e1b7546152 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -212,7 +212,7 @@ golang.org/x/text/transform golang.org/x/text/unicode/norm # golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac ## explicit -# golang.org/x/tools v0.1.6 +# golang.org/x/tools v0.1.7 ## explicit golang.org/x/tools/go/gcexportdata golang.org/x/tools/go/internal/gcimporter