@@ -4780,6 +4780,16 @@ is_import_originated(struct compiler *c, expr_ty e)
4780
4780
return flags & DEF_IMPORT ;
4781
4781
}
4782
4782
4783
+ static void
4784
+ update_location_to_match_attr (struct compiler * c , expr_ty meth )
4785
+ {
4786
+ if (meth -> lineno != meth -> end_lineno ) {
4787
+ // Make start location match attribute
4788
+ c -> u -> u_lineno = meth -> end_lineno ;
4789
+ c -> u -> u_col_offset = meth -> end_col_offset - (int )PyUnicode_GetLength (meth -> v .Attribute .attr )- 1 ;
4790
+ }
4791
+ }
4792
+
4783
4793
// Return 1 if the method call was optimized, -1 if not, and 0 on error.
4784
4794
static int
4785
4795
maybe_optimize_method_call (struct compiler * c , expr_ty e )
@@ -4821,8 +4831,8 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
4821
4831
}
4822
4832
/* Alright, we can optimize the code. */
4823
4833
VISIT (c , expr , meth -> v .Attribute .value );
4824
- int old_lineno = c -> u -> u_lineno ;
4825
- c -> u -> u_lineno = meth -> end_lineno ;
4834
+ SET_LOC ( c , meth ) ;
4835
+ update_location_to_match_attr ( c , meth ) ;
4826
4836
ADDOP_NAME (c , LOAD_METHOD , meth -> v .Attribute .attr , names );
4827
4837
VISIT_SEQ (c , expr , e -> v .Call .args );
4828
4838
@@ -4832,9 +4842,10 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
4832
4842
return 0 ;
4833
4843
};
4834
4844
}
4845
+ SET_LOC (c , e );
4846
+ update_location_to_match_attr (c , meth );
4835
4847
ADDOP_I (c , PRECALL , argsl + kwdsl );
4836
4848
ADDOP_I (c , CALL , argsl + kwdsl );
4837
- c -> u -> u_lineno = old_lineno ;
4838
4849
return 1 ;
4839
4850
}
4840
4851
@@ -7508,6 +7519,7 @@ write_location_info_short_form(struct assembler* a, int length, int column, int
7508
7519
int column_low_bits = column & 7 ;
7509
7520
int column_group = column >> 3 ;
7510
7521
assert (column < 80 );
7522
+ assert (end_column >= column );
7511
7523
assert (end_column - column < 16 );
7512
7524
write_location_first_byte (a , PY_CODE_LOCATION_INFO_SHORT0 + column_group , length );
7513
7525
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)
7579
7591
}
7580
7592
}
7581
7593
else if (i -> i_end_lineno == i -> i_lineno ) {
7582
- if (line_delta == 0 && column < 80 && end_column - column < 16 ) {
7594
+ if (line_delta == 0 && column < 80 && end_column - column < 16 && end_column >= column ) {
7583
7595
write_location_info_short_form (a , isize , column , end_column );
7584
7596
return 1 ;
7585
7597
}
0 commit comments