Skip to content

Incorrect locations for code following case blocks #103971

@marvinweitzel

Description

@marvinweitzel

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 is False 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:

match 1:
    case 1:
        if False:
            print('this should not be executed')
            aVariable = 'somehow, we can hit a breakpoint here'

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:

match 1:
    case 1:
        if True:
            pass
        else:
            anotherVariable = 'somehow, we can hit a breakpoint here, too'

Your environment

python --version
Python 3.11.3
lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.2 LTS
Release:	22.04
Codename:	jammy

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

Metadata

Metadata

Labels

3.11only security fixeseasyinterpreter-core(Objects, Python, Grammar, and Parser dirs)triagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions