Skip to content

Commit ed3b197

Browse files
committed
Fix weird yield from interpreter bug
1 parent d7936f1 commit ed3b197

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

tests/snippets/generators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ def g3():
3232
yield 23
3333
yield from make_numbers()
3434
yield 44
35+
yield from make_numbers()
3536

3637
r = list(g3())
3738
# print(r)
38-
assert r == [23, 1, 2, 3, 44]
39+
assert r == [23, 1, 2, 3, 44, 1, 2, 3]
3940

4041
def g4():
4142
yield

vm/src/frame.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,7 @@ impl Frame {
372372
*self.lasti.borrow_mut() -= 1;
373373
Ok(Some(ExecutionResult::Yield(value)))
374374
}
375-
None => {
376-
// Pop iterator from stack:
377-
self.pop_value();
378-
Ok(None)
379-
}
375+
None => Ok(None),
380376
}
381377
}
382378
bytecode::Instruction::SetupLoop { start, end } => {
@@ -1173,7 +1169,10 @@ impl Frame {
11731169
}
11741170

11751171
fn pop_value(&self) -> PyObjectRef {
1176-
self.stack.borrow_mut().pop().unwrap()
1172+
self.stack
1173+
.borrow_mut()
1174+
.pop()
1175+
.expect("Tried to pop value but there was nothing on the stack")
11771176
}
11781177

11791178
fn pop_multiple(&self, count: usize) -> Vec<PyObjectRef> {

0 commit comments

Comments
 (0)