diff --git a/native/libcst/src/tokenizer/text_position/mod.rs b/native/libcst/src/tokenizer/text_position/mod.rs index 9c394d52..2e58600a 100644 --- a/native/libcst/src/tokenizer/text_position/mod.rs +++ b/native/libcst/src/tokenizer/text_position/mod.rs @@ -117,6 +117,10 @@ impl<'t> TextPosition<'t> { .inner_char_column_number .checked_sub(1) .expect("cannot back up past the beginning of a line."); + self.inner_byte_column_number = self + .inner_byte_column_number + .checked_sub(cw.byte_width) + .expect("cannot back up past the beginning of a line."); self.inner_byte_idx -= cw.byte_width; } else { panic!("Tried to backup past the beginning of the text.") @@ -217,6 +221,7 @@ impl fmt::Debug for TextPosition<'_> { .field("char_widths", &EllipsisDebug) .field("inner_byte_idx", &self.inner_byte_idx) .field("inner_char_column_number", &self.inner_char_column_number) + .field("inner_byte_column_number", &self.inner_byte_column_number) .field("inner_line_number", &self.inner_line_number) .finish() } diff --git a/native/libcst/tests/fixtures/expr.py b/native/libcst/tests/fixtures/expr.py index c1c4e9b7..abb78ab9 100644 --- a/native/libcst/tests/fixtures/expr.py +++ b/native/libcst/tests/fixtures/expr.py @@ -44,6 +44,7 @@ lambda a, b, c=True, *vararg, d=(v1 << 2), e='str', **kwargs : a + b manylambdas = lambda x=lambda y=lambda z=1: z: y(): x() foo = (lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[port_id]) 1 if True else 2 +_ if 0else _ str or None if True else str or bytes or None (str or None) if True else (str or bytes or None) str or None if (1 if True else 2) else str or bytes or None