difftreelog
feat lazily evaluate source field in mergePatch
in: master
5 files changed
crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -1183,6 +1183,12 @@
let entry = receiver.0.new.this_entries.entry(name);
entry.insert_entry(member);
}
+ /// Inserts thunk, replacing if it is already defined
+ pub fn thunk(self, value: impl Into<Thunk<Val>>) {
+ let (receiver, name, member) = self.build_member(MaybeUnbound::Bound(value.into()));
+ let entry = receiver.0.new.this_entries.entry(name);
+ entry.insert_entry(member);
+ }
/// Tries to insert value, returns an error if it was already defined
pub fn try_value(self, value: impl Into<Val>) -> Result<()> {
crates/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,
};
crates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth201 let mut out = ObjValueBuilder::new();201 let mut out = ObjValueBuilder::new();202 for field in target_fields.union(&patch_fields) {202 for field in target_fields.union(&patch_fields) {203 let Some(field_patch) = patch.get(field.clone())? else {203 let Some(field_patch) = patch.get(field.clone())? else {204 // All lazy fields might be unified into a single filtered object core instead of creating a thunk per, but this implementation is good enough.205 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");204 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"));206 out.field(field.clone()).thunk(target_field);205 continue;207 continue;206 };208 };207 if matches!(field_patch, Val::Null) {209 if matches!(field_patch, Val::Null) {tests/golden/issue188.jsonnetdiffbeforeafterboth--- /dev/null
+++ b/tests/golden/issue188.jsonnet
@@ -0,0 +1 @@
+std.mergePatch({ val: error 'should not error' }, {}) + { val+:: {} }
tests/golden/issue188.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/golden/issue188.jsonnet.golden
@@ -0,0 +1 @@
+{ }
\ No newline at end of file