diff --git a/crates/jrsonnet-stdlib/src/sort.rs b/crates/jrsonnet-stdlib/src/sort.rs index c39b1bf4..c72261af 100644 --- a/crates/jrsonnet-stdlib/src/sort.rs +++ b/crates/jrsonnet-stdlib/src/sort.rs @@ -57,7 +57,7 @@ fn sort_identity(mut values: Vec) -> Result> { Val::Str(s) => s.clone(), _ => unreachable!(), }), - SortKeyType::Unknown => unreachable!(), + SortKeyType::Unknown => unreachable!("list is not empty, as checked in sort"), }; Ok(values) } @@ -81,7 +81,7 @@ fn sort_keyf(values: ArrValue, keyf: FuncVal) -> Result>> { Val::Str(s) => s.clone(), _ => unreachable!(), }), - SortKeyType::Unknown => unreachable!(), + SortKeyType::Unknown => unreachable!("list is not empty, as checked in sort"), }; Ok(vk.into_iter().map(|v| v.0).collect()) } @@ -103,13 +103,7 @@ pub fn sort(values: ArrValue, key_getter: FuncVal) -> Result { #[builtin] #[allow(non_snake_case)] pub fn builtin_sort(arr: ArrValue, keyF: Option) -> Result { - if arr.len() <= 1 { - return Ok(arr); - } - super::sort::sort( - arr, - keyF.unwrap_or_else(FuncVal::identity), - ) + super::sort::sort(arr, keyF.unwrap_or_else(FuncVal::identity)) } fn uniq_identity(arr: Vec) -> Result> { @@ -160,6 +154,9 @@ pub fn builtin_uniq(arr: ArrValue, keyF: Option) -> Result { #[builtin] #[allow(non_snake_case)] pub fn builtin_set(arr: ArrValue, keyF: Option) -> Result { + if arr.len() <= 1 { + return Ok(arr); + } let keyF = keyF.unwrap_or(FuncVal::identity()); if keyF.is_identity() { let arr = arr.iter().collect::>>()?;