git.delta.rocks / jrsonnet / refs/commits / 7c5655fe8943

difftreelog

feat lazily evaluate source field in mergePatch

unzkwlwzYaroslav Bolyukin2026-02-08parent: #46ef62a.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
1183 let entry = receiver.0.new.this_entries.entry(name);1183 let entry = receiver.0.new.this_entries.entry(name);
1184 entry.insert_entry(member);1184 entry.insert_entry(member);
1185 }1185 }
1186 /// Inserts thunk, replacing if it is already defined
1187 pub fn thunk(self, value: impl Into<Thunk<Val>>) {
1188 let (receiver, name, member) = self.build_member(MaybeUnbound::Bound(value.into()));
1189 let entry = receiver.0.new.this_entries.entry(name);
1190 entry.insert_entry(member);
1191 }
11861192
1187 /// Tries to insert value, returns an error if it was already defined1193 /// Tries to insert value, returns an error if it was already defined
1188 pub fn try_value(self, value: impl Into<Val>) -> Result<()> {1194 pub fn try_value(self, value: impl Into<Val>) -> Result<()> {
modifiedcrates/jrsonnet-formatter/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-formatter/src/lib.rs
+++ b/crates/jrsonnet-formatter/src/lib.rs
@@ -5,8 +5,7 @@
 	condition_helpers::is_multiple_lines,
 	condition_resolvers::true_resolver,
 	ir_helpers::{new_line_group, with_indent},
-	ConditionResolver, ConditionResolverContext, LineNumber, PrintItemPath, PrintItems,
-	PrintOptions, Signal,
+	ConditionResolver, ConditionResolverContext, LineNumber, PrintItems, PrintOptions,
 };
 use hi_doc::{Formatting, SnippetBuilder};
 use jrsonnet_rowan_parser::{
@@ -14,7 +13,7 @@
 		Arg, ArgsDesc, Assertion, BinaryOperator, Bind, CompSpec, Destruct, DestructArrayPart,
 		DestructRest, Expr, ExprBase, FieldName, ForSpec, IfSpec, ImportKind, Literal, Member,
 		Name, Number, ObjBody, ObjLocal, ParamsDesc, SliceDesc, SourceFile, Stmt, Suffix, Text,
-		Trivia, TriviaKind, UnaryOperator, Visibility,
+		UnaryOperator, Visibility,
 	},
 	AstNode, AstToken as _, SyntaxToken,
 };
modifiedcrates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/misc.rs
+++ b/crates/jrsonnet-stdlib/src/misc.rs
@@ -201,7 +201,9 @@
 	let mut out = ObjValueBuilder::new();
 	for field in target_fields.union(&patch_fields) {
 		let Some(field_patch) = patch.get(field.clone())? else {
-			out.field(field.clone()).value(target.get(field.clone())?.expect("we're iterating over fields union, if field is missing in patch - it exists in target"));
+			// All lazy fields might be unified into a single filtered object core instead of creating a thunk per, but this implementation is good enough.
+			let target_field = target.get_lazy(field.clone()).expect("we're iterating over fields union, if field is missing in patch - it exists in target");
+			out.field(field.clone()).thunk(target_field);
 			continue;
 		};
 		if matches!(field_patch, Val::Null) {
addedtests/golden/issue188.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/tests/golden/issue188.jsonnet
@@ -0,0 +1 @@
+std.mergePatch({ val: error 'should not error' }, {}) + { val+:: {} }
addedtests/golden/issue188.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/tests/golden/issue188.jsonnet.golden
@@ -0,0 +1 @@
+{ }
\ No newline at end of file