Invoking PathEnclosingInterval on the extent of x
in this program:
package p
func f(x int)
gives this result:
Path enclosing interval #18-19 [exact=true]:
[0] *ast.Ident @ 3:8-3:9 (#18-19)
[1] *ast.Field @ 3:8-3:13 (#18-23)
[2] *ast.FieldList @ 3:7-3:14 (#17-24)
[3] *ast.FuncDecl @ 3:1-3:14 (#11-24) Type.Scope={x}
[4] *ast.File @ 1:1-3:14 (#0-24) Scope={}
The FuncType--FuncDecl.Type, which holds the Params FieldList--is nowhere to be seen.
I'm sure this is because the invariant that each node contains its children has an edge case for FuncType: the FuncDecl for func f(x int)
has a FuncType that includes the func
token and the (x int)
signature but not the name f
(FuncDecl.Name), or the receiver for a method.
I'm amazed we haven't noticed this before.
Comment From: gopherbot
Change https://go.dev/cl/595195 mentions this issue: go/ast/astutil: PathEnclosingInterval: add missing FuncType nodes
Comment From: gopherbot
Change https://go.dev/cl/595196 mentions this issue: gopls/internal/golang: splitlines: remove workaround for golang/go#68202
Comment From: findleyr
I'm not surprised we've missed this. We typically care about idents, fields, and decls only. FuncType is a somewhat arbitrary nesting.