bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#30964: python-mode failing "overlapping strings" assertion lately


From: Noam Postavsky
Subject: bug#30964: python-mode failing "overlapping strings" assertion lately
Date: Sat, 02 Jun 2018 16:35:50 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Philipp Stephani <p.stephani2@gmail.com> writes:

>> I think the problem is that the assertion is off by 1, it currently
>> asserts that there is at least one space between strings (because the
>> end position goes *after* the string, while the start position is part
>> of the string).
>>
>> I see the assertion was added in [1: 4fbd330fae].  Phillip, does my
>> proposed change make sense to you?
>
>
> Maybe :-)
> Off-by-one errors are always a bit subtle, so it might definitely be the
> case that there is one. If so, the problem could be further reduced to
> ' '' '
> or similar. Could you add a unit test using such input and make sure that
> it breaks without your patch?

Yeah, the newlines are the important part it seems.

>From 209506955227d3b4de030f817c087bf27e5a7426 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 2 Jun 2018 16:22:17 -0400
Subject: [PATCH] Fix off by one error in python-mode assertion (Bug#30964)

* lisp/progmodes/python.el (python-nav-end-of-statement): Don't assert
that string-start is strictly greater than last-string-end, because
the string end is a position outside of the string and may therefore
be the same as the following string's start.
* test/lisp/progmodes/python-tests.el (python-nav-end-of-statement-2):
New test.
---
 lisp/progmodes/python.el            | 2 +-
 test/lisp/progmodes/python-tests.el | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index c7bb2d97c8..87d2f08fee 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1506,7 +1506,7 @@ python-nav-end-of-statement
                        ;; are somehow out of whack.  This has been
                        ;; observed when using `syntax-ppss' during
                        ;; narrowing.
-                       (cl-assert (> string-start last-string-end)
+                       (cl-assert (>= string-start last-string-end)
                                   :show-args
                                   "Overlapping strings detected")
                        (goto-char string-start)
diff --git a/test/lisp/progmodes/python-tests.el 
b/test/lisp/progmodes/python-tests.el
index 4955da02a2..375bd9588d 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -2004,6 +2004,12 @@ python-tests-visible-string
                 (python-util-forward-comment -1)
                 (point))))))
 
+(ert-deftest python-nav-end-of-statement-2 ()
+  "Test the string overlap assertion (Bug#30964)."
+  (python-tests-with-temp-buffer
+   "'\n''\n"
+   (python-nav-end-of-statement)))
+
 (ert-deftest python-nav-forward-statement-1 ()
   (python-tests-with-temp-buffer
    "
-- 
2.11.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]