google / jsonnet

Jsonnet - The data templating language
http://jsonnet.org
Apache License 2.0
6.87k stars 436 forks source link

Fix field visibility of object comprehension fields to inherit #1140

Closed johnbartholomew closed 4 months ago

johnbartholomew commented 4 months ago

This should make C++ Jsonnet match the existing behaviour of Go-Jsonnet.

Object comprehensions do not support differing field visibility, that is an object comprehension with a "hidden" or "forced-visible" field such as {[k]::1 for k in ["x"]} is rejected with a syntax error.

Intuitively the {[key_expr]: value_expr for x in ...} syntax should behave similarly to a normal (non-comprehension) object that uses default field visibility. Default field visibility is to 'inherit' visibility when merging objects with the + operator, and this is the existing behaviour of Go-Jsonnet.

Example case:

./jsonnet -e '{"one":: "base"} + {[k]: "derived" for k in ["one"]}'

Before this commit, Go-Jsonnet output: { }

Before this commit, C++ Jsonnet output: { "one": "derived" }

After this commit, both produce { }

Fixes #1111