From: Dmitry Gutov <dmitry@gutov.dev>
To: 62761@debbugs.gnu.org
Subject: bug#62761: ruby-add-log-current-method drops some segments when singleton definition references outer module
Date: Tue, 11 Apr 2023 00:02:03 +0300 [thread overview]
Message-ID: <9d81bdc8-355d-7d32-8d3c-361ea0ff585c@gutov.dev> (raw)
[-- Attachment #1: Type: text/plain, Size: 545 bytes --]
Example:
module M
module N
module C
class D
def C.foo
_
end
end
end
end
end
(ruby-add-log-current-method) currently returns "M::C.foo"
While it should return "M::N::C.foo". Patch attached.
This discovery stems from Mattias Engdegård's report (in private) about
an ignored return value from `nreverse`.
Is this good for emacs-29?
It seems pretty safe (with decent test coverage, including the new
test), but probably low urgency. Not a regression either.
[-- Attachment #2: ruby-add-log-reference-containing.diff --]
[-- Type: text/x-patch, Size: 1837 bytes --]
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index beccb8182a7..1199af64821 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1911,7 +1911,7 @@ ruby-add-log-current-method
(while ml
(if (string-equal (car ml) (car mn))
(setq mlist (nreverse (cdr ml)) ml nil))
- (or (setq ml (cdr ml)) (nreverse mlist))))
+ (setq ml (cdr ml))))
(if mlist
(setcdr (last mlist) (butlast mn))
(setq mlist (butlast mn))))
diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el
index 8a75c83d2c3..117385ea3e8 100644
--- a/test/lisp/progmodes/ruby-mode-tests.el
+++ b/test/lisp/progmodes/ruby-mode-tests.el
@@ -567,6 +567,22 @@ ruby-add-log-current-method-namespace-shorthand
(search-backward "_")
(should (string= (ruby-add-log-current-method) "C::D#foo"))))
+(ert-deftest ruby-add-log-current-method-singleton-referencing-outer ()
+ (ruby-with-temp-buffer (ruby-test-string
+ "module M
+ | module N
+ | module C
+ | class D
+ | def C.foo
+ | _
+ | end
+ | end
+ | end
+ | end
+ |end")
+ (search-backward "_")
+ (should (string= (ruby-add-log-current-method) "M::N::C.foo"))))
+
(ert-deftest ruby-add-log-current-method-after-inner-class ()
(ruby-with-temp-buffer (ruby-test-string
"module M
next reply other threads:[~2023-04-10 21:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-10 21:02 Dmitry Gutov [this message]
2023-04-11 5:51 ` bug#62761: ruby-add-log-current-method drops some segments when singleton definition references outer module Eli Zaretskii
2023-04-12 0:17 ` Dmitry Gutov
2023-04-12 6:17 ` Eli Zaretskii
2023-04-12 21:47 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9d81bdc8-355d-7d32-8d3c-361ea0ff585c@gutov.dev \
--to=dmitry@gutov.dev \
--cc=62761@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).