difftreelog
fix accept null as std.slice argument/in slicing syntax
in: master
3 files changed
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -655,11 +655,11 @@
desc: &'static str,
) -> Result<Option<T>> {
if let Some(value) = expr {
- Ok(Some(in_frame(
+ Ok(in_frame(
loc,
|| format!("slice {desc}"),
- || T::from_untyped(evaluate(ctx.clone(), value)?),
- )?))
+ || <Option<T>>::from_untyped(evaluate(ctx.clone(), value)?),
+ )?)
} else {
Ok(None)
}
crates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth655 }655 }656}656}657658impl<T> Typed for Option<T>659where660 T: Typed,661{662 const TYPE: &'static ComplexValType =663 &ComplexValType::UnionRef(&[&ComplexValType::Simple(ValType::Null), T::TYPE]);664665 fn into_untyped(typed: Self) -> Result<Val> {666 typed.map_or_else(|| Ok(Val::Null), |v| T::into_untyped(v))667 }668669 fn from_untyped(untyped: Val) -> Result<Self> {670 if matches!(untyped, Val::Null) {671 Ok(None)672 } else {673 T::from_untyped(untyped).map(Some)674 }675 }676}657677658pub struct NativeFn<D: NativeDesc>(D::Value);678pub struct NativeFn<D: NativeDesc>(D::Value);659impl<D: NativeDesc> Deref for NativeFn<D> {679impl<D: NativeDesc> Deref for NativeFn<D> {crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -48,11 +48,13 @@
#[builtin]
pub fn builtin_slice(
indexable: IndexableVal,
- index: Option<i32>,
- end: Option<i32>,
- step: Option<BoundedUsize<1, { i32::MAX as usize }>>,
+ index: Option<Option<i32>>,
+ end: Option<Option<i32>>,
+ step: Option<Option<BoundedUsize<1, { i32::MAX as usize }>>>,
) -> Result<Val> {
- indexable.slice(index, end, step).map(Val::from)
+ indexable
+ .slice(index.flatten(), end.flatten(), step.flatten())
+ .map(Val::from)
}
#[builtin]