difftreelog
refactor drop default args parser
in: master
2 files changed
crates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/mod.rs
+++ b/crates/jrsonnet-evaluator/src/function/mod.rs
@@ -19,7 +19,6 @@
pub mod builtin;
mod native;
-mod parse;
pub(crate) mod prepared;
pub use jrsonnet_ir::function::*;
crates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth1use std::rc::Rc;23use crate::{4 Context, ContextBuilder, Result, Thunk,5 analyze::LFunction,6 evaluate::{destructure::destruct, evaluate},7};89/// Creates Context with all argument default values applied10/// and with unbound values causing error to be returned.11pub fn parse_default_function_call(body_ctx: Context, func: &Rc<LFunction>) -> Result<Context> {12 let fctx = Context::new_future();13 let mut builder = ContextBuilder::extend(body_ctx, func.params.len());1415 for param in &func.params {16 if let Some(default_expr) = ¶m.default {17 let default_expr = default_expr.clone();18 let fctxc = fctx.clone();19 let thunk = Thunk!(move || {20 let ctx = fctxc.unwrap();21 evaluate(ctx, &default_expr)22 });23 destruct(¶m.destruct, thunk, fctx.clone(), &mut builder);24 } else {25 let name = param.name.clone().unwrap_or_else(|| "<param>".into());26 let thunk = Thunk::errored(27 crate::error::ErrorKind::FunctionParameterNotBoundInCall(28 jrsonnet_ir::function::ParamName::Named(name),29 jrsonnet_ir::function::FunctionSignature::empty(),30 )31 .into(),32 );33 destruct(¶m.destruct, thunk, fctx.clone(), &mut builder);34 }35 }3637 let ctx = builder.build().into_future(fctx);38 Ok(ctx)39}