Skip to content

Commit 815b1d3

Browse files
authored
fix: list_iadd with void (#146)
...also fixed general iadd with other non-list types
1 parent bfc5bb9 commit 815b1d3

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/value/list.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ impl List {
165165
// In case list is not a list, make it a list.
166166
if !list.is("list") {
167167
let item = RefValue::from(list.borrow().clone());
168-
list = Self::list(vec![item], None)?;
168+
if item.is_void() {
169+
*(list.borrow_mut()) = Self::list(vec![], None)?.into();
170+
} else {
171+
*(list.borrow_mut()) = Self::list(vec![item], None)?.into();
172+
}
169173
}
170174

171175
// Extend in-place when possible.

src/value/refvalue.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ impl RefValue {
277277
// When a type name was emitted, try to call builtin-function for operation
278278
if let Some(name) = name {
279279
match Builtin::get_method(name, op) {
280-
Ok(builtin) => return Ok(builtin.call(None, vec![self, operand.ref_or_copy()])?.unwrap()),
280+
Ok(builtin) => {
281+
return Ok(builtin
282+
.call(None, vec![self, operand.ref_or_copy()])?
283+
.unwrap())
284+
}
281285
// default "inline" operation is the non-inline operation assigning the result to itself
282286
Err(_) if op.starts_with("i") => {}
283287
Err(err) => return Err(err),

tests/list_add.tok

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ l += 2
66
l += (3, 4)
77
l
88

9+
# iadd with void
10+
x += (1,2,3)
11+
x
12+
13+
# iadd with int
14+
i = 1
15+
i += (2,3)
16+
i
17+
918
# iadd to itself
1019
a = (1,2)
1120
b = (3,4)
@@ -39,6 +48,10 @@ l
3948

4049
#(1, 2, 3, 4)
4150

51+
#(1, 2, 3)
52+
53+
#(1, 2, 3)
54+
4255
#(1, 2, 3, 4)
4356
#(1, 2)
4457
#(3, 4)

0 commit comments

Comments
 (0)