mirror of
https://github.com/golang/go.git
synced 2025-10-19 19:13:18 +00:00
go/*: use go/types.Func.Signature and go/ast.Preorder
In the few obvious candidates that I found after a bit of grepping. Change-Id: I36af79c46d29e4422bce1f43bbbac9db7de2001a Reviewed-on: https://go-review.googlesource.com/c/go/+/650656 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Commit-Queue: Alan Donovan <adonovan@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
cdc9560794
commit
07a121383c
5 changed files with 9 additions and 12 deletions
|
@ -1058,7 +1058,7 @@ func (w *Walker) emitIfaceType(name string, typ *types.Interface) {
|
||||||
if w.isDeprecated(m) {
|
if w.isDeprecated(m) {
|
||||||
w.emitf("%s //deprecated", m.Name())
|
w.emitf("%s //deprecated", m.Name())
|
||||||
}
|
}
|
||||||
w.emitf("%s%s", m.Name(), w.signatureString(m.Type().(*types.Signature)))
|
w.emitf("%s%s", m.Name(), w.signatureString(m.Signature()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !complete {
|
if !complete {
|
||||||
|
@ -1088,7 +1088,7 @@ func (w *Walker) emitIfaceType(name string, typ *types.Interface) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Walker) emitFunc(f *types.Func) {
|
func (w *Walker) emitFunc(f *types.Func) {
|
||||||
sig := f.Type().(*types.Signature)
|
sig := f.Signature()
|
||||||
if sig.Recv() != nil {
|
if sig.Recv() != nil {
|
||||||
panic("method considered a regular function: " + f.String())
|
panic("method considered a regular function: " + f.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -491,17 +491,14 @@ func findDeclsAndUnresolved(body ast.Node, topDecls map[*ast.Object]ast.Decl, ty
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasIota(s ast.Spec) bool {
|
func hasIota(s ast.Spec) bool {
|
||||||
has := false
|
for n := range ast.Preorder(s) {
|
||||||
ast.Inspect(s, func(n ast.Node) bool {
|
|
||||||
// Check that this is the special built-in "iota" identifier, not
|
// Check that this is the special built-in "iota" identifier, not
|
||||||
// a user-defined shadow.
|
// a user-defined shadow.
|
||||||
if id, ok := n.(*ast.Ident); ok && id.Name == "iota" && id.Obj == nil {
|
if id, ok := n.(*ast.Ident); ok && id.Name == "iota" && id.Obj == nil {
|
||||||
has = true
|
return true
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
return true
|
}
|
||||||
})
|
return false
|
||||||
return has
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// findImportGroupStarts finds the start positions of each sequence of import
|
// findImportGroupStarts finds the start positions of each sequence of import
|
||||||
|
|
|
@ -472,7 +472,7 @@ func verifyInterfaceMethodRecvs(t *testing.T, named *types.Named, level int) {
|
||||||
// check explicitly declared methods
|
// check explicitly declared methods
|
||||||
for i := 0; i < iface.NumExplicitMethods(); i++ {
|
for i := 0; i < iface.NumExplicitMethods(); i++ {
|
||||||
m := iface.ExplicitMethod(i)
|
m := iface.ExplicitMethod(i)
|
||||||
recv := m.Type().(*types.Signature).Recv()
|
recv := m.Signature().Recv()
|
||||||
if recv == nil {
|
if recv == nil {
|
||||||
t.Errorf("%s: missing receiver type", m)
|
t.Errorf("%s: missing receiver type", m)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -525,7 +525,7 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) {
|
||||||
methods := make([]*types.Func, iface.NumExplicitMethods())
|
methods := make([]*types.Func, iface.NumExplicitMethods())
|
||||||
for i := range methods {
|
for i := range methods {
|
||||||
fn := iface.ExplicitMethod(i)
|
fn := iface.ExplicitMethod(i)
|
||||||
sig := fn.Type().(*types.Signature)
|
sig := fn.Signature()
|
||||||
|
|
||||||
recv := types.NewVar(fn.Pos(), fn.Pkg(), "", named)
|
recv := types.NewVar(fn.Pos(), fn.Pkg(), "", named)
|
||||||
methods[i] = types.NewFunc(fn.Pos(), fn.Pkg(), fn.Name(), types.NewSignature(recv, sig.Params(), sig.Results(), sig.Variadic()))
|
methods[i] = types.NewFunc(fn.Pos(), fn.Pkg(), fn.Name(), types.NewSignature(recv, sig.Params(), sig.Results(), sig.Variadic()))
|
||||||
|
|
|
@ -157,7 +157,7 @@ func verifyInterfaceMethodRecvs(t *testing.T, named *types.Named, level int) {
|
||||||
// check explicitly declared methods
|
// check explicitly declared methods
|
||||||
for i := 0; i < iface.NumExplicitMethods(); i++ {
|
for i := 0; i < iface.NumExplicitMethods(); i++ {
|
||||||
m := iface.ExplicitMethod(i)
|
m := iface.ExplicitMethod(i)
|
||||||
recv := m.Type().(*types.Signature).Recv()
|
recv := m.Signature().Recv()
|
||||||
if recv == nil {
|
if recv == nil {
|
||||||
t.Errorf("%s: missing receiver type", m)
|
t.Errorf("%s: missing receiver type", m)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue