-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/passes/printf: add missing call to Func.Origin
A call to an instance of a generic printf wrapper should be checked as a printf wrapper; but a missing call to Func.Origin prevented that. + Test Fixes golang/go#70572 Change-Id: I61de6dc42bfea9b152aabb895ea66962453cb0e4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/631955 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
- Loading branch information
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
go/analysis/passes/printf/testdata/src/issue70572/issue70572.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package issue70572 | ||
|
||
// Regression test for failure to detect that a call to B[bool].Printf | ||
// was printf-like, because of a missing call to types.Func.Origin. | ||
|
||
import "fmt" | ||
|
||
type A struct{} | ||
|
||
func (v A) Printf(format string, values ...any) { // want Printf:"printfWrapper" | ||
fmt.Printf(format, values...) | ||
} | ||
|
||
type B[T any] struct{} | ||
|
||
func (v B[T]) Printf(format string, values ...any) { // want Printf:"printfWrapper" | ||
fmt.Printf(format, values...) | ||
} | ||
|
||
func main() { | ||
var a A | ||
var b B[bool] | ||
a.Printf("x", 1) // want "arguments but no formatting directives" | ||
b.Printf("x", 1) // want "arguments but no formatting directives" | ||
} |