diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-07-26 00:04:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-26 00:04:06 (GMT) |
commit | 01601aa7360ae51e74a64dbe957288096bb364fd (patch) | |
tree | 5b15dacaa20c53e997b0c2cafcd29b0ae3d89ecc /Python | |
parent | 628baf6fef4d633e756024cf813941a4075360c1 (diff) | |
download | cpython-01601aa7360ae51e74a64dbe957288096bb364fd.zip cpython-01601aa7360ae51e74a64dbe957288096bb364fd.tar.gz cpython-01601aa7360ae51e74a64dbe957288096bb364fd.tar.bz2 |
[3.10] bpo-44600: Fix line numbers for pattern matching cleanup code (GH-27346) (GH-27356)
(cherry picked from commit 4214f470f0cb9b6fef9a90758756fbc00ba95b5a)
Co-authored-by: Charles Burkland <charles.aburkland@gmail.com>
Automerge-Triggered-By: GH:brandtbucher
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c index 46660f2..de2a6bf 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -6398,17 +6398,25 @@ compiler_match_inner(struct compiler *c, stmt_ty s, pattern_context *pc) } VISIT_SEQ(c, stmt, m->body); ADDOP_JUMP(c, JUMP_FORWARD, end); + // If the pattern fails to match, we want the line number of the + // cleanup to be associated with the failed pattern, not the last line + // of the body + SET_LOC(c, m->pattern); RETURN_IF_FALSE(emit_and_reset_fail_pop(c, pc)); } if (has_default) { - if (cases == 1) { - // No matches. Done with the subject: - ADDOP(c, POP_TOP); - } // A trailing "case _" is common, and lets us save a bit of redundant // pushing and popping in the loop above: m = asdl_seq_GET(s->v.Match.cases, cases - 1); SET_LOC(c, m->pattern); + if (cases == 1) { + // No matches. Done with the subject: + ADDOP(c, POP_TOP); + } + else { + // Show line coverage for default case (it doesn't create bytecode) + ADDOP(c, NOP); + } if (m->guard) { RETURN_IF_FALSE(compiler_jump_if(c, m->guard, end, 0)); } |