Commit 44e71e5
committed
go/analysis/passes/printf: check anonymous functions too
This change causes the printf analyzer to consider anonymous
functions that are directly assigned to a variable, such as
printf := func(format string, args ...any) { ... }
to be analyzed the same way as an ordinary function. This
allows mistakes calling local printf-wrapper functions to
be reported.
We denote printf-like functions by a types.Object (which
may be a *Func or, now, a *Var) throughout the algorithm.
This generalizes to local and global vars and struct fields,
even ones imported from another package, though since one
cannot export a fact for foreign symbols, the imported var
will only have the wrapper property within the unit that
encloses the assignment.
Also:
- a number of clarifications to identifier names, comments, etc:
- fix a couple of latent printf bugs in x/tools.
+ tests
Change-Id: I82c23dae4a682b574c2b0f4e6daa9be260ae47be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/706635
Reviewed-by: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>1 parent 9095e9b commit 44e71e5
File tree
6 files changed
+378
-147
lines changed- gopls/internal/template
- go/analysis/passes
- nilness
- printf
- testdata/src
- a
- b
6 files changed
+378
-147
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
85 | 95 | | |
86 | 96 | | |
87 | 97 | | |
| |||
0 commit comments