From 815b1d31afed549a15d15aee9daa33a559860c6c Mon Sep 17 00:00:00 2001 From: Jan Max Meyer Date: Sat, 9 Nov 2024 22:14:13 +0100 Subject: [PATCH] fix: `list_iadd` with void (#146) ...also fixed general iadd with other non-list types --- src/value/list.rs | 6 +++++- src/value/refvalue.rs | 6 +++++- tests/list_add.tok | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/value/list.rs b/src/value/list.rs index 5b915bd..eb95f2d 100644 --- a/src/value/list.rs +++ b/src/value/list.rs @@ -165,7 +165,11 @@ impl List { // In case list is not a list, make it a list. if !list.is("list") { let item = RefValue::from(list.borrow().clone()); - list = Self::list(vec![item], None)?; + if item.is_void() { + *(list.borrow_mut()) = Self::list(vec![], None)?.into(); + } else { + *(list.borrow_mut()) = Self::list(vec![item], None)?.into(); + } } // Extend in-place when possible. diff --git a/src/value/refvalue.rs b/src/value/refvalue.rs index 3bf3ece..a0df654 100644 --- a/src/value/refvalue.rs +++ b/src/value/refvalue.rs @@ -277,7 +277,11 @@ impl RefValue { // When a type name was emitted, try to call builtin-function for operation if let Some(name) = name { match Builtin::get_method(name, op) { - Ok(builtin) => return Ok(builtin.call(None, vec![self, operand.ref_or_copy()])?.unwrap()), + Ok(builtin) => { + return Ok(builtin + .call(None, vec![self, operand.ref_or_copy()])? + .unwrap()) + } // default "inline" operation is the non-inline operation assigning the result to itself Err(_) if op.starts_with("i") => {} Err(err) => return Err(err), diff --git a/tests/list_add.tok b/tests/list_add.tok index 19761a5..9659523 100644 --- a/tests/list_add.tok +++ b/tests/list_add.tok @@ -6,6 +6,15 @@ l += 2 l += (3, 4) l +# iadd with void +x += (1,2,3) +x + +# iadd with int +i = 1 +i += (2,3) +i + # iadd to itself a = (1,2) b = (3,4) @@ -39,6 +48,10 @@ l #(1, 2, 3, 4) +#(1, 2, 3) + +#(1, 2, 3) + #(1, 2, 3, 4) #(1, 2) #(3, 4)