fix: ObjExtend should work with non-object lhs - #1120
Draft
He-Pin wants to merge 1 commit into
Draft
Conversation
He-Pin
marked this pull request as draft
September 3, 2026 09:13
He-Pin
force-pushed
the
fix/objextend-nonobject-lhs
branch
from
September 3, 2026 09:19
2900488 to
bf763b2
Compare
Per jsonnet spec, `lhs { body }` is equivalent to `lhs + { body }`.
When lhs is not an object (e.g., string), the expression should fall
back to add semantics instead of throwing a type error.
This matches go-jsonnet behavior (which desugars ApplyBrace to Binary+)
and jrsonnet's recent fix (commit b5fcc2639d).
Changes:
- Evaluator.scala: Handle non-object lhs in visitObjExtend by evaluating
body as standalone object and applying add semantics
- Add test case for string + object concatenation
Example:
"hello" { x: 1 } => "hello{\"x\": 1}"
He-Pin
force-pushed
the
fix/objextend-nonobject-lhs
branch
from
September 3, 2026 09:25
bf763b2 to
8284ca9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
ObjExtend(lhs { body }syntax) to correctly handle non-object lhs values per jsonnet specification.Problem
Per jsonnet spec,
lhs { body }is equivalent tolhs + { body }. When lhs is not an object (e.g., string), sjsonnet was throwing a type error instead of falling back to add semantics.Before:
After:
Solution
Modified
visitObjExtendinEvaluator.scalato:Val.Obj- if so, use existing object extend logicThis matches:
ApplyBracetoBinary +at parse timeevaluate_add_opChanges
sjsonnet/src/sjsonnet/Evaluator.scala: Handle non-object lhs invisitObjExtendsjsonnet/test/resources/new_test_suite/objextend_nonobject_lhs.jsonnet: Test casesjsonnet/test/resources/new_test_suite/objextend_nonobject_lhs.jsonnet.golden: Expected outputTest Plan