golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.73k stars 17.5k forks source link

x/tools/refactor/eg: when matching struct literals, abstract over the tagged/tagless forms #10987

Open alandonovan opened 9 years ago

alandonovan commented 9 years ago

Equivalent struct literals may be written in several ways: T{1, 2} T{a: 1, b: 2} T{b: 2, a: 1} The 'eg' tool should allow a pattern using any of these forms to match any of these expressions. That means internally converting to the named form and doing name-based (not index-based) matching of subtrees. The output should be emitted in the same form as the original.

josharian commented 9 years ago

Also note that the T might not be present in the AST. It can be elided when the struct literal is part of a larger literal (struct, array, map) from which the type can be inferred.