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

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

bug#65209: 30.0.50; Unexpected behaviour of setq-local


From: Stefan Monnier
Subject: bug#65209: 30.0.50; Unexpected behaviour of setq-local
Date: Sun, 13 Aug 2023 15:51:04 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

> Hmm... this is a bug in `make-local-variable` where we do:
>
>   if (blv ? blv->local_if_set
>       : (forwarded && BUFFER_OBJFWDP (valcontents.fwd)))
>     {
>       tem = Fboundp (variable);
>       /* Make sure the symbol has a local value in this particular buffer,
>        by setting it to the same value it already has.  */
>       Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound));
>       return variable;
>     }
>
> I.e. we assume that if a var is `make-variable-buffer-local` then `set`
> will make sure it has a buffer-local value, but this is not true if the
> var is currently let-bound.

The patch below seems to work (for some reason, I'm getting several
errors in `make check` today, but they seems unaffected by this patch
(i.e. I get the same errors in a vanilla build)).


        Stefan


diff --git a/src/data.c b/src/data.c
index 619ab8fde64..6dc3a686aa8 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2213,8 +2213,7 @@ DEFUN ("make-local-variable", Fmake_local_variable, 
Smake_local_variable,
   if (sym->u.s.trapped_write == SYMBOL_NOWRITE)
     xsignal1 (Qsetting_constant, variable);
 
-  if (blv ? blv->local_if_set
-      : (forwarded && BUFFER_OBJFWDP (valcontents.fwd)))
+  if (!blv && (forwarded && BUFFER_OBJFWDP (valcontents.fwd)))
     {
       tem = Fboundp (variable);
       /* Make sure the symbol has a local value in this particular buffer,
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index 680fdd57d71..d93bfec3015 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -768,6 +768,24 @@ data-tests-make-local-forwarded-var
                          (default-value 'last-coding-system-used))
                    '(no-conversion bug34318)))))
 
+(defvar-local data-tests--bug65209 :default-value)
+
+(ert-deftest data-tests-make-local-bug65209 ()
+  (let (vli vlo vgi vgo)
+    (with-temp-buffer
+      (let ((data-tests--bug65209 :let-bound-value))
+        ;; While `setq' would not make the var buffer-local
+        ;; (because we'd be setq-ing the let-binding instead),
+        ;; `setq-local' definitely should.
+        (setq-local data-tests--bug65209 :buffer-local-value)
+        (setq vgi (with-temp-buffer data-tests--bug65209))
+        (setq vli data-tests--bug65209))
+      (setq vgo (with-temp-buffer data-tests--bug65209))
+      (setq vlo data-tests--bug65209))
+    (should (equal (list vli vlo vgi vgo)
+                   '(:buffer-local-value :buffer-local-value
+                     :let-bound-value :default-value)))))
+
 (ert-deftest data-tests-make_symbol_constant ()
   "Can't set variable marked with 'make_symbol_constant'."
   (should-error (setq most-positive-fixnum 1) :type 'setting-constant))






reply via email to

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