]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: update golang.org/x/tools to CL 645697, and revendor
authorRob Findley <rfindley@google.com>
Fri, 31 Jan 2025 15:06:15 +0000 (15:06 +0000)
committerRobert Findley <rfindley@google.com>
Fri, 31 Jan 2025 16:42:32 +0000 (08:42 -0800)
go get golang.org/x/tools@9874647 # CL 645697
go mod tidy
go mod vendor

Fixes #71485

Change-Id: I72d8f82abd0c6e05f2698d8a372bf9485002d1b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/645336
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Robert Findley <rfindley@google.com>
TryBot-Bypass: Robert Findley <rfindley@google.com>

src/cmd/go.mod
src/cmd/go.sum
src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/printf.go
src/cmd/vendor/modules.txt

index b29321de7b42449a2ff640c53e868d5bdcccbcc6..9c29c3ac74d197e991578cbef9d14f033978345a 100644 (file)
@@ -11,7 +11,7 @@ require (
        golang.org/x/sys v0.28.0
        golang.org/x/telemetry v0.0.0-20241204182053-c0ac0e154df3
        golang.org/x/term v0.27.0
-       golang.org/x/tools v0.28.0
+       golang.org/x/tools v0.28.1-0.20250131145412-98746475647e
 )
 
 require (
index 5c262454d5b6535ca34052e95f8c167f144e1ddf..593063a9daa35156d0863cef93c02beb8b7dfe9d 100644 (file)
@@ -22,7 +22,7 @@ golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
 golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
 golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
 golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
-golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
-golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
+golang.org/x/tools v0.28.1-0.20250131145412-98746475647e h1:6Kzwg7JxW2HRWToKpIKqlpF8l8XMasoALX3OcAMdgL8=
+golang.org/x/tools v0.28.1-0.20250131145412-98746475647e/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
 rsc.io/markdown v0.0.0-20240306144322-0bf8f97ee8ef h1:mqLYrXCXYEZOop9/Dbo6RPX11539nwiCNBb1icVPmw8=
 rsc.io/markdown v0.0.0-20240306144322-0bf8f97ee8ef/go.mod h1:8xcPgWmwlZONN1D9bjxtHEjrUtSEa3fakVF8iaewYKQ=
index 171ad2013722c418c88098d99a123df60c018040..011ea8bef629256a21f87a6ead7ad394962653bb 100644 (file)
@@ -25,6 +25,7 @@ import (
        "golang.org/x/tools/go/ast/inspector"
        "golang.org/x/tools/go/types/typeutil"
        "golang.org/x/tools/internal/typeparams"
+       "golang.org/x/tools/internal/versions"
 )
 
 func init() {
@@ -108,12 +109,12 @@ func (f *isWrapper) String() string {
        }
 }
 
-func run(pass *analysis.Pass) (interface{}, error) {
+func run(pass *analysis.Pass) (any, error) {
        res := &Result{
                funcs: make(map[*types.Func]Kind),
        }
        findPrintfLike(pass, res)
-       checkCall(pass)
+       checkCalls(pass)
        return res, nil
 }
 
@@ -182,7 +183,7 @@ func maybePrintfWrapper(info *types.Info, decl ast.Decl) *printfWrapper {
 }
 
 // findPrintfLike scans the entire package to find printf-like functions.
-func findPrintfLike(pass *analysis.Pass, res *Result) (interface{}, error) {
+func findPrintfLike(pass *analysis.Pass, res *Result) (any, error) {
        // Gather potential wrappers and call graph between them.
        byObj := make(map[*types.Func]*printfWrapper)
        var wrappers []*printfWrapper
@@ -409,20 +410,29 @@ func stringConstantExpr(pass *analysis.Pass, expr ast.Expr) (string, bool) {
        return "", false
 }
 
-// checkCall triggers the print-specific checks if the call invokes a print function.
-func checkCall(pass *analysis.Pass) {
+// checkCalls triggers the print-specific checks for calls that invoke a print
+// function.
+func checkCalls(pass *analysis.Pass) {
        inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
        nodeFilter := []ast.Node{
+               (*ast.File)(nil),
                (*ast.CallExpr)(nil),
        }
+
+       var fileVersion string // for selectively suppressing checks; "" if unknown.
        inspect.Preorder(nodeFilter, func(n ast.Node) {
-               call := n.(*ast.CallExpr)
-               fn, kind := printfNameAndKind(pass, call)
-               switch kind {
-               case KindPrintf, KindErrorf:
-                       checkPrintf(pass, kind, call, fn)
-               case KindPrint:
-                       checkPrint(pass, call, fn)
+               switch n := n.(type) {
+               case *ast.File:
+                       fileVersion = versions.Lang(versions.FileVersion(pass.TypesInfo, n))
+
+               case *ast.CallExpr:
+                       fn, kind := printfNameAndKind(pass, n)
+                       switch kind {
+                       case KindPrintf, KindErrorf:
+                               checkPrintf(pass, fileVersion, kind, n, fn)
+                       case KindPrint:
+                               checkPrint(pass, n, fn)
+                       }
                }
        })
 }
@@ -503,7 +513,7 @@ type formatState struct {
 }
 
 // checkPrintf checks a call to a formatted print routine such as Printf.
-func checkPrintf(pass *analysis.Pass, kind Kind, call *ast.CallExpr, fn *types.Func) {
+func checkPrintf(pass *analysis.Pass, fileVersion string, kind Kind, call *ast.CallExpr, fn *types.Func) {
        idx := formatStringIndex(pass, call)
        if idx < 0 || idx >= len(call.Args) {
                return
@@ -517,7 +527,17 @@ func checkPrintf(pass *analysis.Pass, kind Kind, call *ast.CallExpr, fn *types.F
                // non-constant format string and no arguments:
                // if msg contains "%", misformatting occurs.
                // Report the problem and suggest a fix: fmt.Printf("%s", msg).
-               if !suppressNonconstants && idx == len(call.Args)-1 {
+               //
+               // However, as described in golang/go#71485, this analysis can produce a
+               // significant number of diagnostics in existing code, and the bugs it
+               // finds are sometimes unlikely or inconsequential, and may not be worth
+               // fixing for some users. Gating on language version allows us to avoid
+               // breaking existing tests and CI scripts.
+               if !suppressNonconstants &&
+                       idx == len(call.Args)-1 &&
+                       fileVersion != "" && // fail open
+                       versions.AtLeast(fileVersion, "go1.24") {
+
                        pass.Report(analysis.Diagnostic{
                                Pos: formatArg.Pos(),
                                End: formatArg.End(),
index 281989b1e2c5c2b0aff42c21614621e7cd4a8e4b..118646d75c4ccbe6ea3ac4f2771bb55cfb48daab 100644 (file)
@@ -73,7 +73,7 @@ golang.org/x/text/internal/tag
 golang.org/x/text/language
 golang.org/x/text/transform
 golang.org/x/text/unicode/norm
-# golang.org/x/tools v0.28.0
+# golang.org/x/tools v0.28.1-0.20250131145412-98746475647e
 ## explicit; go 1.22.0
 golang.org/x/tools/cmd/bisect
 golang.org/x/tools/cover