diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2022-10-19 09:48:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-19 09:48:50 (GMT) |
commit | 9be05df3997de3fe9d34525871baa375cbccd7fc (patch) | |
tree | 70a9d1b68aade5d465f3e9fa9310692e5677d1b4 /Python | |
parent | e4ec8de6fa6f0a07e64f6a3e3f894926b4b0652d (diff) | |
download | cpython-9be05df3997de3fe9d34525871baa375cbccd7fc.zip cpython-9be05df3997de3fe9d34525871baa375cbccd7fc.tar.gz cpython-9be05df3997de3fe9d34525871baa375cbccd7fc.tar.bz2 |
gh-98398: Fix source locations for 'assert' bytecode (GH-98405)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Python/compile.c b/Python/compile.c index 4d5b41a..c888f40 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3960,7 +3960,6 @@ compiler_from_import(struct compiler *c, stmt_ty s) static int compiler_assert(struct compiler *c, stmt_ty s) { - location loc = LOC(s); /* Always emit a warning if the test is a non-zero length tuple */ if ((s->v.Assert.test->kind == Tuple_kind && asdl_seq_LEN(s->v.Assert.test->v.Tuple.elts) > 0) || @@ -3968,23 +3967,26 @@ compiler_assert(struct compiler *c, stmt_ty s) PyTuple_Check(s->v.Assert.test->v.Constant.value) && PyTuple_Size(s->v.Assert.test->v.Constant.value) > 0)) { - if (!compiler_warn(c, loc, "assertion is always true, " - "perhaps remove parentheses?")) + if (!compiler_warn(c, LOC(s), "assertion is always true, " + "perhaps remove parentheses?")) { return 0; } } - if (c->c_optimize) + if (c->c_optimize) { return 1; + } NEW_JUMP_TARGET_LABEL(c, end); - if (!compiler_jump_if(c, &loc, s->v.Assert.test, end, 1)) + location loc = LOC(s); + if (!compiler_jump_if(c, &loc, s->v.Assert.test, end, 1)) { return 0; - ADDOP(c, loc, LOAD_ASSERTION_ERROR); + } + ADDOP(c, LOC(s), LOAD_ASSERTION_ERROR); if (s->v.Assert.msg) { VISIT(c, expr, s->v.Assert.msg); - ADDOP_I(c, loc, CALL, 0); + ADDOP_I(c, LOC(s), CALL, 0); } - ADDOP_I(c, loc, RAISE_VARARGS, 1); + ADDOP_I(c, LOC(s), RAISE_VARARGS, 1); USE_LABEL(c, end); return 1; |