x/tools/go/ast/astutil: Apply should not traverse Sel of SelectorExpr #28440
Labels
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)? go version go1.11.1 linux/amd64Does this issue reproduce with the latest release? yes
What operating system and processor architecture are you using (
go env
)?OARCH="amd64"
GOBIN=""
GOCACHE="/home/dvd/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dvd/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/dvd/work/infergo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build174838993=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Read the source code and ran tests.
astutil.go:
What did you expect to see?
I expect to NOT see line 248.
What did you see instead?
Apply traverses Sel field of SelectorExpr as a child. This is not composable: although Sel is an Ident node implementing ast.Expr, it is not an expression. What happens is that the user has to check in the Ident case that the parent is not SelectorExpr or the field is not "Sel". It is much better in my opinion to just let the API user to process Sel in the SelectorExpr.
Not traversing children of SelectorExpr is not a great workaround either because X (the first field) can be as complicated a tree as one wishes.
The text was updated successfully, but these errors were encountered: