Skip to content

Commit 6a199e1

Browse files
committed
Fix: f_lineno after return should point to the return line
PullRequest: graalpython/3584
2 parents 2730986 + 4a23483 commit 6a199e1

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -55,6 +55,50 @@ def test_nested():
5555
f = test_nested()
5656
assert f.f_lineno == 53
5757

58+
# IMPORTANT: DO NOT MOVE!
59+
def test_nested_lineno_return_loc():
60+
def test_nested():
61+
f = sys._getframe(0)
62+
if True:
63+
return f
64+
return None
65+
66+
f = test_nested()
67+
assert f.f_lineno == 63
68+
69+
# IMPORTANT: DO NOT MOVE!
70+
def test_nested_lineno_implicit_return():
71+
f = None
72+
def test_nested():
73+
nonlocal f
74+
f = sys._getframe(0)
75+
dummy = 42
76+
77+
test_nested()
78+
assert f.f_lineno == 75
79+
80+
# IMPORTANT: DO NOT MOVE!
81+
def test_nested_lineno_finally():
82+
def test_nested():
83+
try:
84+
return sys._getframe(0)
85+
finally:
86+
dummy = 42
87+
88+
f = test_nested()
89+
assert f.f_lineno == 86, f.f_lineno
90+
91+
# IMPORTANT: DO NOT MOVE!
92+
def test_nested_lineno_multiline_return():
93+
def test_nested():
94+
f = sys._getframe(0)
95+
if f:
96+
return (
97+
f)
98+
return None
99+
100+
f = test_nested()
101+
assert f.f_lineno == 96
58102

59103
def test_read_and_write_locals():
60104
a = 1

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,7 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
18301830
throw bytecodeRaiseVarargs(virtualFrame, stackTop, beginBci, count, localNodes);
18311831
}
18321832
case OpCodesConstants.RETURN_VALUE: {
1833+
setCurrentBci(virtualFrame, bciSlot, bci);
18331834
return bytecodeReturnValue(virtualFrame, isGeneratorOrCoroutine, instrumentation, mutableData, stackTop, tracingOrProfilingEnabled, beginBci);
18341835
}
18351836
case OpCodesConstants.LOAD_BUILD_CLASS: {

0 commit comments

Comments
 (0)