git.delta.rocks / jrsonnet / refs/commits / 456a1bbb3515

difftreelog

fix derive names for full destruction

Yaroslav Bolyukin2022-04-24parent: #b2f480a.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth
44
5use crate::{5use crate::{
6 error::{Error::*, Result},6 error::{Error::*, Result},
7 evaluate, evaluate_method,7 evaluate, evaluate_method, evaluate_named,
8 gc::GcHashMap,8 gc::GcHashMap,
9 tb, throw,9 tb, throw,
10 val::ThunkValue,10 val::ThunkValue,
235 BindSpec::Field { into, value } => {235 BindSpec::Field { into, value } => {
236 #[derive(Trace)]236 #[derive(Trace)]
237 struct EvaluateThunkValue {237 struct EvaluateThunkValue {
238 name: Option<IStr>,
238 fctx: Pending<Context>,239 fctx: Pending<Context>,
239 expr: LocExpr,240 expr: LocExpr,
240 }241 }
241 impl ThunkValue for EvaluateThunkValue {242 impl ThunkValue for EvaluateThunkValue {
242 type Output = Val;243 type Output = Val;
243 fn get(self: Box<Self>, s: State) -> Result<Self::Output> {244 fn get(self: Box<Self>, s: State) -> Result<Self::Output> {
245 if let Some(name) = self.name {
246 evaluate_named(s, self.fctx.unwrap(), &self.expr, name)
247 } else {
244 evaluate(s, self.fctx.unwrap(), &self.expr)248 evaluate(s, self.fctx.unwrap(), &self.expr)
245 }249 }
250 }
246 }251 }
247 // TODO: Generate some name, as destructure spec may be used with plain functions
248 let data = Thunk::new(tb!(EvaluateThunkValue {252 let data = Thunk::new(tb!(EvaluateThunkValue {
253 name: into.name(),
249 fctx,254 fctx,
250 expr: value.clone(),255 expr: value.clone(),
251 }));256 }));
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -204,6 +204,15 @@
 		rest: Option<DestructRest>,
 	},
 }
+impl Destruct {
+	pub fn name(&self) -> Option<IStr> {
+		match self {
+			Self::Full(name) => Some(name.clone()),
+			#[cfg(feature = "exp-destruct")]
+			_ => None,
+		}
+	}
+}
 
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
 #[derive(Debug, Clone, PartialEq, Trace)]