GH-94694: Fix column offsets for multi-line method lookups (GH-94697)

This commit is contained in:
Brandt Bucher 2022-07-09 17:22:23 -07:00 committed by GitHub
parent a10cf2f6b3
commit 264b3ddfd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 2 deletions

View file

@ -4736,8 +4736,15 @@ 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_loc.lineno = meth->end_lineno;
c->u->u_loc.col_offset = meth->end_col_offset - (int)PyUnicode_GetLength(meth->v.Attribute.attr)-1;
c->u->u_loc.lineno = c->u->u_loc.end_lineno = meth->end_lineno;
int len = (int)PyUnicode_GET_LENGTH(meth->v.Attribute.attr);
if (len <= meth->end_col_offset) {
c->u->u_loc.col_offset = meth->end_col_offset - len;
}
else {
// GH-94694: Somebody's compiling weird ASTs. Just drop the columns:
c->u->u_loc.col_offset = c->u->u_loc.end_col_offset = -1;
}
}
}