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

Support setting and iterating over map keys #511

Open negz opened 9 months ago

negz commented 9 months ago

Fixes https://github.com/google/starlark-go/issues/381

This PR introduces a new MapField type, which can be used to set and access map field values by key.

Without this PR I get a panic in toStarlark1 where x.Message() is called on a map field value. (Perhaps because my proto has some map<string, Message> fields):

panic: type mismatch: cannot convert map to message

I've also updated the nascent proto.star unit tests to use their own proto file, to test repeated and map fields.

Separately from the main change, I've included a commit that adds a list-like append method to RepeatedField. I can break that out into a separate PR if you'd prefer.