From cb42a92673ddf191c75750ce3c529eba796c936e Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Sun, 14 Jun 2026 10:41:25 +0200 Subject: [PATCH] fix(stdlib): pop also removes last item from type definition --- src/stdlib/pop.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/stdlib/pop.rs b/src/stdlib/pop.rs index a8632c8050..bcf3782a86 100644 --- a/src/stdlib/pop.rs +++ b/src/stdlib/pop.rs @@ -72,10 +72,19 @@ impl FunctionExpression for PopFn { } fn type_def(&self, state: &state::TypeState) -> TypeDef { - self.value + let mut typedef = self.value .type_def(state) .fallible_unless(Kind::array(Collection::any())) - .restrict_array() + .restrict_array(); + + // Remove last element from type definition if array contains just know elements + if let Some(col) = typedef.kind_mut().as_array_mut() { + if col.unknown_kind().is_undefined() { + col.known_mut().pop_last(); + } + } + + typedef } } @@ -108,7 +117,6 @@ mod tests { Index::from(2) => Kind::integer(), Index::from(3) => Kind::boolean(), Index::from(4) => Kind::float(), - Index::from(5) => Kind::bytes(), }), } @@ -119,9 +127,7 @@ mod tests { Index::from(0) => Kind::integer(), Index::from(1) => Kind::integer(), Index::from(2) => Kind::integer(), - Index::from(3) => Kind::integer(), }), } - ]; }