google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.26k stars 204 forks source link

Walk syntax.DictEntry instead of ignoring it #447

Closed yuxincs closed 1 year ago

yuxincs commented 1 year ago

*syntax.DictExpr has a field List []Expr which is supposed to only contain *syntax.DictEntrys:

https://github.com/google/starlark-go/blob/d7da88764354917a82dfa84a8ae1cb04f107ab78/syntax/syntax.go#L377

However, when we are walking *syntax.DictExpr node in syntax.Walk function, we are ignoring *syntax.DictEntrys, directly unwrapping it, and then continuing the walk recursions. This means the caller will not be able to "see" a *syntax.DictEntry node when calling the walk function.

This PR fixes this by directly walking on each element of the List field, which in turn will be automatically handled by the *syntax.DictEntry case in Walk.

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

yuxincs commented 1 year ago

CLA is now cleared so this PR is good to go 😃