Skip to content

Commit 095a0cc

Browse files
committed
fix f_lineno
1 parent 4861863 commit 095a0cc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crates/vm/src/builtins/frame.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ impl Frame {
6464

6565
#[pygetset]
6666
pub fn f_lineno(&self) -> usize {
67-
self.current_location().line.get()
67+
// If lasti is 0, execution hasn't started yet - use first line number
68+
// Similar to PyCode_Addr2Line which returns co_firstlineno for addr_q < 0
69+
if self.lasti() == 0 {
70+
self.code.first_line_number.map(|n| n.get()).unwrap_or(1)
71+
} else {
72+
self.current_location().line.get()
73+
}
6874
}
6975

7076
#[pygetset]

0 commit comments

Comments
 (0)