diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2022-06-16 10:56:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-16 10:56:35 (GMT) |
commit | df091e14d8c5b25b9094ebb86857e30adc8e5abb (patch) | |
tree | 099e40124823defc9d684955632e06ccafd0c924 /Python | |
parent | 6e280326625eb5235131c0105cf72720419fcfda (diff) | |
download | cpython-df091e14d8c5b25b9094ebb86857e30adc8e5abb.zip cpython-df091e14d8c5b25b9094ebb86857e30adc8e5abb.tar.gz cpython-df091e14d8c5b25b9094ebb86857e30adc8e5abb.tar.bz2 |
[3.11] GH-93662: Make sure that column offsets are correct in multi-line method calls. (GH-93673) (#93895)
Co-authored-by: Mark Shannon <mark@hotpy.org>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c index cc0d76e..6d800b2 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4780,6 +4780,16 @@ is_import_originated(struct compiler *c, expr_ty e) return flags & DEF_IMPORT; } +static void +update_location_to_match_attr(struct compiler *c, expr_ty meth) +{ + if (meth->lineno != meth->end_lineno) { + // Make start location match attribute + c->u->u_lineno = meth->end_lineno; + c->u->u_col_offset = meth->end_col_offset - (int)PyUnicode_GetLength(meth->v.Attribute.attr)-1; + } +} + // Return 1 if the method call was optimized, -1 if not, and 0 on error. static int maybe_optimize_method_call(struct compiler *c, expr_ty e) @@ -4821,8 +4831,8 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e) } /* Alright, we can optimize the code. */ VISIT(c, expr, meth->v.Attribute.value); - int old_lineno = c->u->u_lineno; - c->u->u_lineno = meth->end_lineno; + SET_LOC(c, meth); + update_location_to_match_attr(c, meth); ADDOP_NAME(c, LOAD_METHOD, meth->v.Attribute.attr, names); VISIT_SEQ(c, expr, e->v.Call.args); @@ -4832,9 +4842,10 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e) return 0; }; } + SET_LOC(c, e); + update_location_to_match_attr(c, meth); ADDOP_I(c, PRECALL, argsl + kwdsl); ADDOP_I(c, CALL, argsl + kwdsl); - c->u->u_lineno = old_lineno; return 1; } @@ -7508,6 +7519,7 @@ write_location_info_short_form(struct assembler* a, int length, int column, int int column_low_bits = column & 7; int column_group = column >> 3; assert(column < 80); + assert(end_column >= column); assert(end_column - column < 16); write_location_first_byte(a, PY_CODE_LOCATION_INFO_SHORT0 + column_group, length); write_location_byte(a, (column_low_bits << 4) | (end_column - column)); @@ -7579,7 +7591,7 @@ write_location_info_entry(struct assembler* a, struct instr* i, int isize) } } else if (i->i_end_lineno == i->i_lineno) { - if (line_delta == 0 && column < 80 && end_column - column < 16) { + if (line_delta == 0 && column < 80 && end_column - column < 16 && end_column >= column) { write_location_info_short_form(a, isize, column, end_column); return 1; } |