tools/go/analysis/passes
Daniel Martí 2de7f9bf82 go/analysis/passes/structtag: allow field tag shadowing
In the following piece of code:

	type T1 struct {
		Shadowed string `json:"foo"`
	}
	type T2 struct {
		T1
		Shadowing int `json:"foo"`
	}

encoding/json will encode T2 using T2.Shadowing, ignoring T2.Shadowed
entirely. This can be a useful feature to replace some of T1's fields
when encoding it. Moreover, this feature is already in use in the wild,
even though it's probably never been documented.

This started being a problem, as the structtag pass started walking
through embedded fields a few months ago. To keep it from complaining
about these useful shadowing cases, make it only see duplicate field tag
names if they are at the same embedding level, in which case no
shadowing is happening.

The old code indexed these tags by encoding key and name, using a
[2]string. The new code needs to add a level integer, so start declaring
named types for the map, and use methods to simplify the code further
below. We still use a map pointer, to avoid allocating on every single
struct definition.

Updates golang/go#30846.

Change-Id: Iae53228d4f8bd91584c59dcc982cb1300970bc8f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179360
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-06-02 11:28:58 +00:00
..
asmdecl go/analysis/passes: fix bugs discovered in std 2019-05-09 15:32:22 +00:00
assign go/analysis/passes: add doc and copyright comments 2018-10-16 20:28:15 +00:00
atomic go/analysis/passes: add doc and copyright comments 2018-10-16 20:28:15 +00:00
atomicalign Revert "go/analysis/passes/atomicalign: handle pointers to struct" 2019-02-02 20:26:10 +00:00
bools go/analysis/passes/bools: eliminate quadratic runtime, output 2019-05-13 18:47:35 +00:00
buildssa go/analysis/passes/nilness: degenerate nil condition checker 2018-10-19 00:59:45 +00:00
buildtag go/analysis/passes: add doc and copyright comments 2018-10-16 20:28:15 +00:00
cgocall go/{analysis,packages}: add TypesSizes 2019-01-17 19:41:23 +00:00
composite go/analysis/passes/composite: add an example to the doc 2019-01-24 19:20:49 +00:00
copylock go/analysis/passes: add doc and copyright comments 2018-10-16 20:28:15 +00:00
ctrlflow go/analysis/passes: add doc and copyright comments 2018-10-16 20:28:15 +00:00
deepequalerrors go/analysis/passes/deepequalerrors: check for reflect.DeepEqual on errors 2019-02-28 17:43:37 +00:00
errorsas errorsas: handle single-actual case 2019-06-01 11:02:25 +00:00
findcall go/analysis/cmd/analyze: install all analyzers 2018-10-19 17:03:54 +00:00
httpresponse go/analysis/passes/httpresponse: split out from vet 2018-10-16 19:47:10 +00:00
inspect go/analysis: fix typos and update documentation 2019-01-11 18:03:38 +00:00
internal/analysisutil go/analysis/passes/assign: split out from vet 2018-10-08 20:59:24 +00:00
loopclosure go/analysis/passes: add doc and copyright comments 2018-10-16 20:28:15 +00:00
lostcancel lostcancel: do not analyze cancel variable which defined outside current function scope 2019-05-08 02:57:53 +00:00
nilfunc go/analysis/passes: add doc and copyright comments 2018-10-16 20:28:15 +00:00
nilness go/analysis/passes/nilness: degenerate nil condition checker 2018-10-19 00:59:45 +00:00
pkgfact go/analysis/internal/unitchecker: a 'go vet'-compatible driver 2018-11-02 17:49:05 +00:00
printf cmd/vet: verify potentially-recursive Stringers are actually Stringers 2019-04-25 15:00:28 +00:00
shadow go/analysis/passes/shadow: add shadow command 2018-11-08 22:19:41 +00:00
shift go/{analysis,packages}: add TypesSizes 2019-01-17 19:41:23 +00:00
stdmethods go/analysis/passes: fix bugs discovered in std 2019-05-09 15:32:22 +00:00
structtag go/analysis/passes/structtag: allow field tag shadowing 2019-06-02 11:28:58 +00:00
tests go/analysis/passes/tests: add pointer to where test name conventions are specified 2019-05-29 20:33:03 +00:00
unmarshal go/analysis/passes: fix bugs discovered in std 2019-05-09 15:32:22 +00:00
unreachable go/analysis/passes: add doc and copyright comments 2018-10-16 20:28:15 +00:00
unsafeptr go/analysis: unindent some pieces of code 2018-11-19 11:39:21 +00:00
unusedresult go/analysis/passes: add doc and copyright comments 2018-10-16 20:28:15 +00:00
README go/analysis/internal/checker: analysis driver based on go/packages 2018-09-26 01:25:07 +00:00

README

This directory does not contain a Go package,
but acts as a container for various analyses
that implement the golang.org/x/tools/go/analysis
API and may be imported into an analysis tool.

By convention, each package foo provides the analysis,
and each command foo/cmd/foo provides a standalone driver.