From 52973eb0f8011de9ffd0524572bd44e41d49dd00 Mon Sep 17 00:00:00 2001 From: Dummi26 Date: Thu, 30 Mar 2023 18:46:45 +0200 Subject: [PATCH] changed remove and pop to return [] or [v] instead of [] or v to remove the ambiguity when successfully returning v with v = []. This also makes .assume1() work with these functions. --- src/script/builtins.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/script/builtins.rs b/src/script/builtins.rs index 7779b9a..7148e33 100644 --- a/src/script/builtins.rs +++ b/src/script/builtins.rs @@ -391,7 +391,14 @@ impl BuiltinFunction { } Self::Pop | Self::Remove | Self::Get => { if let Some(v) = input.first() { - v.get_any().expect("cannot use get on this type") + VType { + types: vec![ + VSingleType::Tuple(vec![]), + VSingleType::Tuple(vec![v + .get_any() + .expect("cannot use get on this type")]), + ], + } } else { unreachable!("get, pop or remove called without args") } @@ -1144,7 +1151,12 @@ impl BuiltinFunction { if args.len() == 1 { if let VDataEnum::Reference(v) = args[0].run(vars, libs).data { if let VDataEnum::List(_, v) = &mut v.lock().unwrap().data { - v.pop().unwrap_or_else(|| VDataEnum::Tuple(vec![]).to()) + if let Some(v) = v.pop() { + VDataEnum::Tuple(vec![v]) + } else { + VDataEnum::Tuple(vec![]) + } + .to() } else { unreachable!("pop: not a list") } @@ -1162,7 +1174,8 @@ impl BuiltinFunction { { if let VDataEnum::List(_, v) = &mut v.lock().unwrap().data { if v.len() > i as _ && i >= 0 { - v.remove(i as _) + let v = v.remove(i as _); + VDataEnum::Tuple(vec![v]).to() } else { VDataEnum::Tuple(vec![]).to() }