Skip to content

Commit 62c7f8c

Browse files
Fix: Preserve original sequence type when slicing tuples in 'slice_val'.
1 parent 7bea4f1 commit 62c7f8c

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

compiler/src/modules/vm/collections.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ impl<'a> VM<'a> {
196196
}
197197
_ => return Err(VmErr::Type("slice".into())),
198198
};
199-
self.heap.alloc(HeapObj::List(Rc::new(RefCell::new(result))))
199+
match self.heap.get(obj) {
200+
HeapObj::Tuple(_) => self.heap.alloc(HeapObj::Tuple(result)),
201+
_ => self.heap.alloc(HeapObj::List(Rc::new(RefCell::new(result)))),
202+
}
200203
}
201204

202205
/*

compiler/tests/cases/vm_cases.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,7 @@
112112
{"src": "print(round(2.5))", "output": ["2"], "result": "None"},
113113
{"src": "print(list(zip([1,2],[3,4],[5,6])))", "output": ["[(1, 3, 5), (2, 4, 6)]"], "result": "None"},
114114
{"src": "a, b = [1, 2, 3]", "output": [], "result": "None", "error": "expected 2 values to unpack, got 3"},
115-
{"src": "a, b, c = [1, 2]", "output": [], "result": "None", "error": "expected 3 values to unpack, got 2"}
115+
{"src": "a, b, c = [1, 2]", "output": [], "result": "None", "error": "expected 3 values to unpack, got 2"},
116+
{"src": "t = (1,2,3,4,5)\nprint(type(t[1:3]))","output": ["tuple"],"result": "None"},
117+
{"src": "l = [1,2,3,4,5]\nprint(type(l[1:3]))","output": ["list"],"result": "None"}
116118
]

0 commit comments

Comments
 (0)