-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Incorrect locations for code following case
blocks
#103971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Confirmed that this happens with 3.11: 0 0 RESUME 0
1 2 LOAD_CONST 0 (1)
2 4 LOAD_CONST 0 (1)
6 COMPARE_OP 2 (==)
12 POP_JUMP_FORWARD_IF_FALSE 3 (to 20)
3 14 NOP
5 16 LOAD_CONST 4 (None)
18 RETURN_VALUE
2 >> 20 LOAD_CONST 4 (None)
22 RETURN_VALUE
3.12(main): 0 0 RESUME 0
1 2 LOAD_CONST 0 (1)
2 4 LOAD_CONST 0 (1)
6 COMPARE_OP 40 (==)
10 POP_JUMP_IF_FALSE 1 (to 14)
3 12 RETURN_CONST 1 (None)
2 >> 14 RETURN_CONST 1 (None)
Not 100% sure if this is a bug that we want to fix in 3.11? 3.10 is already closed for bug fix right? We need expertise from the compiler side. |
Yeah, this is a bug, and should be fixed in 3.11. From a first glance, this should be as simple as saving and restoring the current location when entering/exiting Any takers? Otherwise, I can pick it up. |
There are two places where |
This will also need one or more regression tests for the cases shown here. Thankfully, we already have good scaffolding for that in Even though the bug is only in 3.11, I'd like to see the tests forward-ported to 3.12 after. |
I reproduced this in IDLE's debugger. Either 'Go' or 'Step, Step, Step' skips over line 4 to line 5, but a subsequent Go/Step does not execute line 5. Change line 5 to a print and is is skipped as expected. IDLE Debugger uses a subclass of bdb, so the bug is not in pdb. |
Yep, this is a compiler bug (3.12 cleaned up how we handle locations to avoid issues like this, which is why it's silently fixed there). |
…3-04-28-18-57-13.gh-issue-103971.Q3U9lv.rst
I just wanted to say how much I appreciate your responses and your extremely fast investigation of this issue. Thanks a lot for taking this seriously! |
case
blocks
case
blockscase
blocks
Uh oh!
There was an error while loading. Please reload this page.
Bug report
In the following example, the debugger hits a breakpoint that is set in the
aVariable = ...
line, which is in an if-statement whose condition isFalse
and which should therefore not be executed. When I run the example with coverage (under PyCharm 2023.1), that line turns green. The print statement is not executed, which matches the expectation.The assignment does not actually happen. It somehow just hits the line without really executing it.
Minimal reproducible example:
The same happens, if the last statement in the unreachable code is a pass. If I replace it with e.g. a
print()
statement, then everything behaves as expected.If we extend the example a little bit, that behavior is reproducible for an unreachable else block, too:
Your environment
I initially encountered that behavior in a 3.10 version. Due to the fact that I thought, I could fix it with an upgrade to 3.11, I don't know the exact minor version of 3.10.
I double-checked this with the first online Python debugger that I could find and it behaves the same way.
Linked PRs
The text was updated successfully, but these errors were encountered: