summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-07-10 00:22:23 (GMT)
committerGitHub <noreply@github.com>2022-07-10 00:22:23 (GMT)
commit264b3ddfd561d97204ffb30be6a7d1fb0555e560 (patch)
tree7c18cb52295ed1a678fdbd1e9d0722ff70eba84c /Python/compile.c
parenta10cf2f6b3766f9dbbe54bdaacfb3f2ca406ea3d (diff)
downloadcpython-264b3ddfd561d97204ffb30be6a7d1fb0555e560.zip
cpython-264b3ddfd561d97204ffb30be6a7d1fb0555e560.tar.gz
cpython-264b3ddfd561d97204ffb30be6a7d1fb0555e560.tar.bz2
GH-94694: Fix column offsets for multi-line method lookups (GH-94697)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Python/compile.c b/Python/compile.c
index f36a6e8..427fb2a 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -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;
+ }
}
}