Skip to content

Commit

Permalink
go/analysis/passes/printf: permit multiple %w format verbs
Browse files Browse the repository at this point in the history
For golang/go#53435

Change-Id: Icdc664585fbcf7ac07ef92df8b43b20c1d7733e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/432576
Run-TryBot: Damien Neil <dneil@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
neild committed Sep 22, 2022
1 parent b3ab50b commit 1877b5f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
6 changes: 0 additions & 6 deletions go/analysis/passes/printf/printf.go
Expand Up @@ -583,7 +583,6 @@ func checkPrintf(pass *analysis.Pass, kind Kind, call *ast.CallExpr, fn *types.F
argNum := firstArg
maxArgNum := firstArg
anyIndex := false
anyW := false
for i, w := 0, 0; i < len(format); i += w {
w = 1
if format[i] != '%' {
Expand All @@ -606,11 +605,6 @@ func checkPrintf(pass *analysis.Pass, kind Kind, call *ast.CallExpr, fn *types.F
pass.Reportf(call.Pos(), "%s does not support error-wrapping directive %%w", state.name)
return
}
if anyW {
pass.Reportf(call.Pos(), "%s call has more than one error-wrapping directive %%w", state.name)
return
}
anyW = true
}
if len(state.argNums) > 0 {
// Continue with the next sequential argument.
Expand Down
2 changes: 1 addition & 1 deletion go/analysis/passes/printf/testdata/src/a/a.go
Expand Up @@ -342,7 +342,7 @@ func PrintfTests() {
_ = fmt.Errorf("%[2]w %[1]s", "x", err) // OK
_ = fmt.Errorf("%[2]w %[1]s", e, "x") // want `fmt.Errorf format %\[2\]w has arg "x" of wrong type string`
_ = fmt.Errorf("%w", "x") // want `fmt.Errorf format %w has arg "x" of wrong type string`
_ = fmt.Errorf("%w %w", err, err) // want `fmt.Errorf call has more than one error-wrapping directive %w`
_ = fmt.Errorf("%w %w", err, err) // OK
_ = fmt.Errorf("%w", interface{}(nil)) // want `fmt.Errorf format %w has arg interface{}\(nil\) of wrong type interface{}`
_ = fmt.Errorf("%w", errorTestOK(0)) // concrete value implements error
_ = fmt.Errorf("%w", errSubset) // interface value implements error
Expand Down

0 comments on commit 1877b5f

Please sign in to comment.