Subject: bug#76730: 29.3; gv-define-setter defect

From: Michael Heerdegen <[email-masked]>
Date: Wed, 05 Mar 2025 16:38:18 +0100

Devon Sean McCullough <[email-masked]> writes:

> A better expansion such as
>
> (let* ((v (make-overlay 1 2))
>        (s (- (overlay-end v) 1)))
>   (progn
>     (move-overlay v (overlay-start v) s)
>     s))
>
> looks ok and should pacify the byte compiler.

Agreed.  This should do it:

From 30d3ee71753aa9f8527a28b15295ccb421e7c8c0 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <[email-masked]>
Date: Wed, 5 Mar 2025 16:09:30 +0100
Subject: [PATCH] Fix overlay-start and overlay-end gv setters

This fixes Bug#76730.

* lisp/emacs-lisp/gv.el (overlay-start, overlay-end):
Avoid computing the set value twice.
---
 lisp/emacs-lisp/gv.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index b2390d65817..8e69c8d0447 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -400,9 +400,11 @@ keymap-parent
 (gv-define-simple-setter match-data set-match-data 'fix)
 (gv-define-simple-setter overlay-get overlay-put)
 (gv-define-setter overlay-start (store ov)
-  `(progn (move-overlay ,ov ,store (overlay-end ,ov)) ,store))
+  (macroexp-let2 nil store store
+    `(progn (move-overlay ,ov ,store (overlay-end ,ov)) ,store)))
 (gv-define-setter overlay-end (store ov)
-  `(progn (move-overlay ,ov (overlay-start ,ov) ,store) ,store))
+  (macroexp-let2 nil store store
+    `(progn (move-overlay ,ov (overlay-start ,ov) ,store) ,store)))
 (gv-define-simple-setter process-buffer set-process-buffer)
 (gv-define-simple-setter process-filter set-process-filter)
 (gv-define-simple-setter process-sentinel set-process-sentinel)
--
2.39.5

> P.P.S.  I won't ask why the warning points to the top-level form
> rather than the offending line.

This works well for me (in master).  Guess it has been improved since
29.3.

Michael.