@@ -4801,6 +4801,16 @@ is_import_originated(struct compiler *c, expr_ty e)
4801
4801
return flags & DEF_IMPORT ;
4802
4802
}
4803
4803
4804
+ static void
4805
+ update_location_to_match_attr (struct compiler * c , expr_ty meth )
4806
+ {
4807
+ if (meth -> lineno != meth -> end_lineno ) {
4808
+ // Make start location match attribute
4809
+ c -> u -> u_lineno = meth -> end_lineno ;
4810
+ c -> u -> u_col_offset = meth -> end_col_offset - (int )PyUnicode_GetLength (meth -> v .Attribute .attr )- 1 ;
4811
+ }
4812
+ }
4813
+
4804
4814
// Return 1 if the method call was optimized, -1 if not, and 0 on error.
4805
4815
static int
4806
4816
maybe_optimize_method_call (struct compiler * c , expr_ty e )
@@ -4842,8 +4852,8 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
4842
4852
}
4843
4853
/* Alright, we can optimize the code. */
4844
4854
VISIT (c , expr , meth -> v .Attribute .value );
4845
- int old_lineno = c -> u -> u_lineno ;
4846
- c -> u -> u_lineno = meth -> end_lineno ;
4855
+ SET_LOC ( c , meth ) ;
4856
+ update_location_to_match_attr ( c , meth ) ;
4847
4857
ADDOP_NAME (c , LOAD_METHOD , meth -> v .Attribute .attr , names );
4848
4858
VISIT_SEQ (c , expr , e -> v .Call .args );
4849
4859
@@ -4853,8 +4863,9 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
4853
4863
return 0 ;
4854
4864
};
4855
4865
}
4866
+ SET_LOC (c , e );
4867
+ update_location_to_match_attr (c , meth );
4856
4868
ADDOP_I (c , CALL , argsl + kwdsl );
4857
- c -> u -> u_lineno = old_lineno ;
4858
4869
return 1 ;
4859
4870
}
4860
4871
@@ -7673,6 +7684,7 @@ write_location_info_short_form(struct assembler* a, int length, int column, int
7673
7684
int column_low_bits = column & 7 ;
7674
7685
int column_group = column >> 3 ;
7675
7686
assert (column < 80 );
7687
+ assert (end_column >= column );
7676
7688
assert (end_column - column < 16 );
7677
7689
write_location_first_byte (a , PY_CODE_LOCATION_INFO_SHORT0 + column_group , length );
7678
7690
write_location_byte (a , (column_low_bits << 4 ) | (end_column - column ));
@@ -7744,7 +7756,7 @@ write_location_info_entry(struct assembler* a, struct instr* i, int isize)
7744
7756
}
7745
7757
}
7746
7758
else if (i -> i_end_lineno == i -> i_lineno ) {
7747
- if (line_delta == 0 && column < 80 && end_column - column < 16 ) {
7759
+ if (line_delta == 0 && column < 80 && end_column - column < 16 && end_column >= column ) {
7748
7760
write_location_info_short_form (a , isize , column , end_column );
7749
7761
return 1 ;
7750
7762
}
0 commit comments