]> Cypherpunks repositories - gostls13.git/commitdiff
go/*: use go/types.Func.Signature and go/ast.Preorder
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 19 Feb 2025 22:35:48 +0000 (22:35 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 20 Feb 2025 03:25:33 +0000 (19:25 -0800)
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>

src/cmd/api/main_test.go
src/go/doc/example.go
src/go/internal/gcimporter/gcimporter_test.go
src/go/internal/gcimporter/ureader.go
src/go/internal/srcimporter/srcimporter_test.go

index a0820c2274c4787f5cb6b99ca38b558df233c074..ed366be4e7726791f5fac110ef9f65c91394467f 100644 (file)
@@ -1058,7 +1058,7 @@ func (w *Walker) emitIfaceType(name string, typ *types.Interface) {
                if w.isDeprecated(m) {
                        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 {
@@ -1088,7 +1088,7 @@ func (w *Walker) emitIfaceType(name string, typ *types.Interface) {
 }
 
 func (w *Walker) emitFunc(f *types.Func) {
-       sig := f.Type().(*types.Signature)
+       sig := f.Signature()
        if sig.Recv() != nil {
                panic("method considered a regular function: " + f.String())
        }
index 7a8c26291db1f20746133bf5ad1fba405fece7e1..5c03c6612f981a4e6270693f0efc3eef676370f2 100644 (file)
@@ -491,17 +491,14 @@ func findDeclsAndUnresolved(body ast.Node, topDecls map[*ast.Object]ast.Decl, ty
 }
 
 func hasIota(s ast.Spec) bool {
-       has := false
-       ast.Inspect(s, func(n ast.Node) bool {
+       for n := range ast.Preorder(s) {
                // Check that this is the special built-in "iota" identifier, not
                // a user-defined shadow.
                if id, ok := n.(*ast.Ident); ok && id.Name == "iota" && id.Obj == nil {
-                       has = true
-                       return false
+                       return true
                }
-               return true
-       })
-       return has
+       }
+       return false
 }
 
 // findImportGroupStarts finds the start positions of each sequence of import
index b92c9c9c962b209d593441fb33b2b46ca1b12b0f..caf2d6f8e30cc001afe99a2d3201fe7bb49f1a40 100644 (file)
@@ -472,7 +472,7 @@ func verifyInterfaceMethodRecvs(t *testing.T, named *types.Named, level int) {
        // check explicitly declared methods
        for i := 0; i < iface.NumExplicitMethods(); i++ {
                m := iface.ExplicitMethod(i)
-               recv := m.Type().(*types.Signature).Recv()
+               recv := m.Signature().Recv()
                if recv == nil {
                        t.Errorf("%s: missing receiver type", m)
                        continue
index 88f27641c9c54b68d3743bd65e2d409f53a5608a..3432f08d85012d35a5338c309c56d5092f9687c4 100644 (file)
@@ -525,7 +525,7 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) {
                                methods := make([]*types.Func, iface.NumExplicitMethods())
                                for i := range methods {
                                        fn := iface.ExplicitMethod(i)
-                                       sig := fn.Type().(*types.Signature)
+                                       sig := fn.Signature()
 
                                        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()))
index 87dfdc75bb2bbf3cef9ad37a3061b40491c50010..5adb8831a940d23df722bba15cf3f7c502db2320 100644 (file)
@@ -157,7 +157,7 @@ func verifyInterfaceMethodRecvs(t *testing.T, named *types.Named, level int) {
        // check explicitly declared methods
        for i := 0; i < iface.NumExplicitMethods(); i++ {
                m := iface.ExplicitMethod(i)
-               recv := m.Type().(*types.Signature).Recv()
+               recv := m.Signature().Recv()
                if recv == nil {
                        t.Errorf("%s: missing receiver type", m)
                        continue