GNU bug report logs - #5950
defvaralias after defvar should be warned in runtime

Previous Next

Package: emacs;

Reported by: irieshinsuke <at> yahoo.co.jp

Date: Thu, 15 Apr 2010 05:15:02 UTC

Severity: normal

Tags: fixed, patch

Fixed in version 27.1

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 5950 in the body.
You can then email your comments to 5950 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Thu, 15 Apr 2010 05:15:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to irieshinsuke <at> yahoo.co.jp:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 15 Apr 2010 05:15:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>
To: bug-gnu-emacs <at> gnu.org
Subject: defvaralias after defvar should be warned in runtime
Date: Thu, 15 Apr 2010 14:13:58 +0900
Please consider below:

We assume an user wrote .emacs file as:

 (setq old-foo 123)
 (load "bar")

Here, bar.el includes the following:

 (defvar foo 456)
 (define-obsolete-variable-alias 'old-foo 'foo)

By this .emacs setting, the user probably hopes `old-foo' remains 123
after loading bar.el, but actually it will be changed to 456. This
behavior is inconsistent with the principle that `defvar' must not
override existing value, so bar.el should be modified as:

 (define-obsolete-variable-alias 'old-foo 'foo)
 (defvar foo 456)

I think the programs like bar.el should be warned when running (and
byte-compiling, if possible).

-- 
IRIE Shinsuke, Ph.D.





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Wed, 15 Sep 2010 20:14:02 GMT) Full text and rfc822 format available.

Message #8 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>
Cc: 5950 <at> debbugs.gnu.org
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Wed, 15 Sep 2010 16:16:03 -0400
IRIE Shinsuke wrote:

> We assume an user wrote .emacs file as:
>
>  (setq old-foo 123)
>  (load "bar")
>
> Here, bar.el includes the following:
>
>  (defvar foo 456)
>  (define-obsolete-variable-alias 'old-foo 'foo)
>
> By this .emacs setting, the user probably hopes `old-foo' remains 123
> after loading bar.el, but actually it will be changed to 456.
[...]
> I think the programs like bar.el should be warned when running (and
> byte-compiling, if possible).


You can never have too many compilation warnings...

Here is an attempt at this. Comments:

1) It gives a spurious warning in cases where the
define-obsolete-variable-alias statement is autoloaded. One could
simply reposition such statements anyway.

2) I never know when to use normal-call or keep-pending.

It does reveal a couple of bugs in the current trunk.


*** lisp/emacs-lisp/bytecomp.el	2010-09-15 15:30:43 +0000
--- lisp/emacs-lisp/bytecomp.el	2010-09-15 18:59:50 +0000
***************
*** 3874,3879 ****
--- 3874,3892 ----
    (byte-compile-set-symbol-position 'lambda)
    (error "`lambda' used as function name is invalid"))
  
+ (put 'define-obsolete-variable-alias 'byte-hunk-handler
+      'byte-compile-define-obsolete-variable-alias)
+ ;; Gives a spurious warning if the d-o-v-a is autoloaded.
+ (defun byte-compile-define-obsolete-variable-alias (form)
+   (and (byte-compile-warning-enabled-p 'suspicious)
+        (eq (car-safe (nth 2 form)) 'quote)
+        (memq (car-safe (cdr (nth 2 form))) byte-compile-bound-variables)
+        (not (memq (cadr (nth 2 form)) byte-compile-const-variables))
+        (byte-compile-warn "variable `%s' aliased after definition"
+ 			  (cadr (nth 2 form))))
+   (byte-compile-keep-pending form)
+   nil)
+ 
  ;; Compile normally, but deal with warnings for the function being defined.
  (put 'defalias 'byte-hunk-handler 'byte-compile-file-form-defalias)
  (defun byte-compile-file-form-defalias (form)





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Thu, 16 Sep 2010 00:43:02 GMT) Full text and rfc822 format available.

Message #11 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 5950 <at> debbugs.gnu.org
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Thu, 16 Sep 2010 09:44:55 +0900
I think the byte-hunk-handler should be put to `defvaralias' rather than
`define-obsolete-variable-alias'. `defvaralias' is a primitive function
which causes the problem in `define-obsolete-variable-alias' macro.

Thanks.

IRIE Shinsuke




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Thu, 16 Sep 2010 03:49:02 GMT) Full text and rfc822 format available.

Message #14 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>
Cc: 5950 <at> debbugs.gnu.org
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Wed, 15 Sep 2010 23:51:00 -0400
IRIE Shinsuke wrote:

> I think the byte-hunk-handler should be put to `defvaralias' rather than
> `define-obsolete-variable-alias'. `defvaralias' is a primitive function
> which causes the problem in `define-obsolete-variable-alias' macro.

The issue _is_ with defvaralias, but it's only a problem for user
options, things that might be set in .emacs before the associated
alias definition is evaluated. It's hard to see why there should be
non-obsolete aliases to user options, it just causes confusion. I
think there would be false positives if the warning was associated
with defvaralias, which is mostly used with non-user-options, I would
think.

The last time a similar issue came up, Stefan preferred that only
define-obsolete-variable-alias be changed; see

http://debbugs.gnu.org/cgi/bugreport.cgi?bug=4706#21




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Thu, 16 Sep 2010 09:26:02 GMT) Full text and rfc822 format available.

Message #17 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 5950 <at> debbugs.gnu.org, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Thu, 16 Sep 2010 11:27:57 +0200
>> I think the byte-hunk-handler should be put to `defvaralias' rather than
>> `define-obsolete-variable-alias'. `defvaralias' is a primitive function
>> which causes the problem in `define-obsolete-variable-alias' macro.
> The issue _is_ with defvaralias, but it's only a problem for user
> options, things that might be set in .emacs before the associated
> alias definition is evaluated.  It's hard to see why there should be
> non-obsolete aliases to user options, it just causes confusion.  I
> think there would be false positives if the warning was associated
> with defvaralias, which is mostly used with non-user-options, I would
> think.

> The last time a similar issue came up, Stefan preferred that only
> define-obsolete-variable-alias be changed; see

Well, in this case I'd rather check defvaralias, since the problem is
there: if (defvaralias 'foo 'bar) is executed after both `foo' and `bar'
have been given values, then it will necessarily have to drop one of the
two, which is the source of the problem.

Changing defvaralias to try and be more clever would definitely
be wrong.  But changing it to output a warning about the problematic
situation would be OK and changing the byte-compiler to output a warning
in cases that make such a situation more likely is also perfectly good.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Sat, 26 May 2018 16:54:02 GMT) Full text and rfc822 format available.

Message #20 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: Glenn Morris <rgm <at> gnu.org>, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 5950 <at> debbugs.gnu.org
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Sat, 26 May 2018 12:52:48 -0400
[Message part 1 (text/plain, inline)]
tags 5950 + patch
quit

Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:

> Changing defvaralias to try and be more clever would definitely
> be wrong.  But changing it to output a warning about the problematic
> situation would be OK and changing the byte-compiler to output a warning
> in cases that make such a situation more likely is also perfectly good.

I see the byte-compiler side of this has been taken care of [1..4], but
I still managed to make this mistake when I made a cross-file alias
(Bug#31603).  Here's a patch for the runtime warning.  While writing it,
I found that invoking `display-warning' failed during bootstrap, so the
first commit works around that.  In the end it's not strictly necessary,
because I added a check to suppress the warning when the two variables
have `eq' values, so no warnings are generated during bootstrap anyway.

The bootstrap warnings were about cl-custom-print-functions,
mail-dont-reply-to-names, and several flymake-proc-* variables all of
which correctly have the alias before the definition.  This makes me
think I might be doing something wrong, but it seems to do the right
thing in my tests.

[v1-0001-Let-display-warning-work-during-bootstrap.patch (text/x-diff, inline)]
From e039d38c653059716b68f64fdc7b395bf7593834 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Fri, 25 May 2018 21:37:17 -0400
Subject: [PATCH v1 1/2] Let display-warning work during bootstrap

* lisp/emacs-lisp/warnings.el (display-warning): Only call
`special-mode' and `newline' if they are `fbound'.
---
 lisp/emacs-lisp/warnings.el | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/warnings.el b/lisp/emacs-lisp/warnings.el
index 665733181c..c4d97ceab0 100644
--- a/lisp/emacs-lisp/warnings.el
+++ b/lisp/emacs-lisp/warnings.el
@@ -241,11 +241,15 @@ display-warning
 	       (old (get-buffer buffer-name))
 	       (buffer (or old (get-buffer-create buffer-name)))
 	       (level-info (assq level warning-levels))
+               ;; `newline' may be unbound during bootstrap.
+               (newline (if (fboundp 'newline) #'newline
+                          (lambda () (insert "\n"))))
 	       start end)
 	  (with-current-buffer buffer
 	    ;; If we created the buffer, disable undo.
 	    (unless old
-	      (special-mode)
+	      (when (fboundp 'special-mode) ; Undefined during bootstrap.
+                (special-mode))
 	      (setq buffer-read-only t)
 	      (setq buffer-undo-list t))
 	    (goto-char (point-max))
@@ -256,7 +260,7 @@ display-warning
 			(funcall warning-series)))))
 	    (let ((inhibit-read-only t))
 	      (unless (bolp)
-		(newline))
+		(funcall newline))
 	      (setq start (point))
 	      (if warning-prefix-function
 		  (setq level-info (funcall warning-prefix-function
@@ -264,7 +268,7 @@ display-warning
 	      (insert (format (nth 1 level-info)
 			      (format warning-type-format typename))
 		      message)
-	      (newline)
+              (funcall newline)
 	      (when (and warning-fill-prefix (not (string-match "\n" message)))
 		(let ((fill-prefix warning-fill-prefix)
 		      (fill-column 78))
-- 
2.11.0

[v1-0002-Give-warning-if-losing-value-to-defvaralias-Bug-5.patch (text/x-diff, inline)]
From 6fe5dee5f4ad0a6e18d73658d0392d4444ff1826 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Fri, 25 May 2018 08:40:55 -0400
Subject: [PATCH v1 2/2] Give warning if losing value to defvaralias (Bug#5950)

* src/eval.c (Fdefvaralias): Call `display-warning' if the alias
target has a non-eq value to the variable being aliased.
* test/src/eval-tests.el (defvaralias-overwrite-warning): New test.
---
 src/eval.c             | 10 ++++++++++
 test/src/eval-tests.el | 22 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/src/eval.c b/src/eval.c
index 90d8c33518..354ab2c2d1 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -623,6 +623,16 @@ DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
   if (NILP (Fboundp (base_variable)))
     set_internal (base_variable, find_symbol_value (new_alias),
                   Qnil, SET_INTERNAL_BIND);
+  else if (!NILP (Fboundp (new_alias))
+           && !EQ (find_symbol_value (new_alias),
+                   find_symbol_value (base_variable)))
+    call2 (intern ("display-warning"),
+           list3 (intern ("defvaralias"), intern ("losing-value"), new_alias),
+           CALLN (Fformat_message,
+                  build_string
+                  ("Overwriting value of `%s' by aliasing to `%s'"),
+                  new_alias, base_variable));
+
   {
     union specbinding *p;
 
diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el
index 319dd91c86..281d959b53 100644
--- a/test/src/eval-tests.el
+++ b/test/src/eval-tests.el
@@ -26,6 +26,7 @@
 ;;; Code:
 
 (require 'ert)
+(eval-when-compile (require 'cl-lib))
 
 (ert-deftest eval-tests--bug24673 ()
   "Check that Bug#24673 has been fixed."
@@ -117,4 +118,25 @@ eval-tests--exceed-specbind-limit
   "Check that Bug#31072 is fixed."
   (should-error (eval '(defvar 1) t) :type 'wrong-type-argument))
 
+(ert-deftest defvaralias-overwrite-warning ()
+  "Test for Bug#5950."
+  (defvar eval-tests--foo)
+  (setq eval-tests--foo 2)
+  (defvar eval-tests--foo-alias)
+  (setq eval-tests--foo-alias 1)
+  (cl-letf (((symbol-function 'display-warning)
+             (lambda (type &rest _)
+               (throw 'got-warning type))))
+    ;; Warn if we lose a value through aliasing.
+    (should (equal
+             '(defvaralias losing-value eval-tests--foo-alias)
+             (catch 'got-warning
+               (defvaralias 'eval-tests--foo-alias 'eval-tests--foo))))
+    ;; Don't warn if we don't.
+    (makunbound 'eval-tests--foo-alias)
+    (should (eq 'no-warning
+                (catch 'got-warning
+                  (defvaralias 'eval-tests--foo-alias 'eval-tests--foo)
+                  'no-warning)))))
+
 ;;; eval-tests.el ends here
-- 
2.11.0

[Message part 4 (text/plain, inline)]

[1: 495963cfaf]: 2018-04-20 17:22:47 -0400
  * lisp/emacs-lisp/bytecomp.el (byte-compile-file-form-defvar-function):
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=495963cfaf535646350051f47c085b84319572f0

[2: 9c3eeba4db]: 2018-04-20 18:34:39 -0400
  The tedious game of whack-a-mole with compiler warnings continues
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=9c3eeba4db26ddaeead100beea7a96f9fa640918

[3: 18de2ada24]: 2018-04-20 18:55:04 -0400
  More alias-related tedium
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=18de2ada243653ece98b18044233e5d29eee5903

[4: 94e794c8d8]: 2018-04-20 19:02:16 -0400
  Tweak recent bytecomp defvaralias change
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=94e794c8d8b93a1d6813742da12135f2746ef80b

Added tag(s) patch. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 26 May 2018 16:54:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Sat, 26 May 2018 19:47:01 GMT) Full text and rfc822 format available.

Message #25 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: Glenn Morris <rgm <at> gnu.org>, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 5950 <at> debbugs.gnu.org
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Sat, 26 May 2018 15:46:03 -0400
> +  else if (!NILP (Fboundp (new_alias))
> +           && !EQ (find_symbol_value (new_alias),
> +                   find_symbol_value (base_variable)))
> +    call2 (intern ("display-warning"),
> +           list3 (intern ("defvaralias"), intern ("losing-value"), new_alias),
> +           CALLN (Fformat_message,
> +                  build_string
> +                  ("Overwriting value of `%s' by aliasing to `%s'"),
> +                  new_alias, base_variable));

I'd make it just a `message` rather than a `display-warning`.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Sat, 26 May 2018 23:55:02 GMT) Full text and rfc822 format available.

Message #28 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: Glenn Morris <rgm <at> gnu.org>, 5950 <at> debbugs.gnu.org,
 IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Sat, 26 May 2018 19:54:34 -0400
>> The bootstrap warnings were about cl-custom-print-functions,
>> mail-dont-reply-to-names,

Oh, it's because the definition gets into loaddefs.el, but the alias
doesn't.

>> and several flymake-proc-* variables all of
>> which correctly have the alias before the definition.

Not 100% sure about the flymake ones, but I guess it's some double
loading during bootstrap.


Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:

> I'd make it just a `message` rather than a `display-warning`.

Hmm, I think it's too easy to overlook that, I prefer the in-your-face
nature of display-warning.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Tue, 12 Jun 2018 11:49:02 GMT) Full text and rfc822 format available.

Message #31 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: Glenn Morris <rgm <at> gnu.org>, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 5950 <at> debbugs.gnu.org
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Tue, 12 Jun 2018 07:48:40 -0400
tags 5950 fixed
close 5950 27.1
quit

Noam Postavsky <npostavs <at> gmail.com> writes:

> Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:
>
>> I'd make it just a `message` rather than a `display-warning`.
>
> Hmm, I think it's too easy to overlook that, I prefer the in-your-face
> nature of display-warning.

Pushed to master.

[1: c912db0836]: 2018-06-12 07:40:33 -0400
  Give warning if losing value to defvaralias (Bug#5950)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=c912db0836f6975519dea57fb0a4adc2988da1b1




Added tag(s) fixed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 12 Jun 2018 11:49:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 27.1, send any further explanations to 5950 <at> debbugs.gnu.org and irieshinsuke <at> yahoo.co.jp Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 12 Jun 2018 11:49:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 11 Jul 2018 11:24:05 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 02 Aug 2018 02:04:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Thu, 02 Aug 2018 02:15:01 GMT) Full text and rfc822 format available.

Message #42 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: 5950 <at> debbugs.gnu.org
Cc: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Wed, 01 Aug 2018 22:14:05 -0400
[Message part 1 (text/plain, inline)]
[forwarding to list, original didn't make it because bug was archived]

[Message part 2 (message/rfc822, inline)]
From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Wed, 1 Aug 2018 14:55:56 -0400
Hi Noam,

I just updated my Emacs and ran into this warning, but I have no idea
what's wrong with the following code :)

  (defvaralias 'flycheck-python-pylint-executable 'python-shell-interpreter)
  (defvaralias 'flycheck-python-flake8-executable 'python-shell-interpreter)

These two variables `flycheck-&-executable' are configuration knobs
created by Flycheck, and I never want to set them individually; instead,
I want them to have the same value as `python-shell-interpreter'.  While
the code above works, it also pops a "warning" buffer now:

Warning (defvaralias): Overwriting value of ‘flycheck-python-pylint-executable’ by aliasing to ‘python-shell-interpreter’
Warning (defvaralias): Overwriting value of ‘flycheck-python-flake8-executable’ by aliasing to ‘python-shell-interpreter’

I've set warning-suppress-log-types to '(defvaralias losing-value) to
work around this, but was the warning actually intended in this case?

Clément.
[Message part 3 (text/plain, inline)]

It's warning because you overwrite the original value of
flycheck-python-pylint-executable when you call defvaralias.  In this
case you intended that, but usually it's a mistake.

You could make the warning suppression more selective by adding
(defvaralias losing-value flycheck-python-pylint-executable) and
(defvaralias losing-value flycheck-python-flake8-executable) to
warning-suppress-log-types.

Alternatively, you could do

  (setq flycheck-python-pylint-executable python-shell-interpreter)
  (defvaralias 'flycheck-python-pylint-executable 'python-shell-interpreter)
  (setq flycheck-python-flake8-executable python-shell-interpreter)
  (defvaralias 'flycheck-python-flake8-executable 'python-shell-interpreter)

(the warning doesn't trigger if the value being overwritten is `eq' to
the new one).


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Thu, 02 Aug 2018 13:09:01 GMT) Full text and rfc822 format available.

Message #45 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 5950 <at> debbugs.gnu.org, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Thu, 2 Aug 2018 09:08:30 -0400
On 2018-08-01 17:46, Stefan Monnier wrote:
>> Warning (defvaralias): Overwriting value of
>> ‘flycheck-python-pylint-executable’ by aliasing to
>> ‘python-shell-interpreter’
> 
> This warning tells you that the variable
> `flycheck-python-pylint-executable` already had a value before the call
> to `defvaralias`, and that this value is lost at this point.
> 
> Usually the warning is due to the defvaralias call being performed after
> the corresponding `defvar`s.

Right. But why is that a problem?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Thu, 02 Aug 2018 13:29:02 GMT) Full text and rfc822 format available.

Message #48 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: 5950 <at> debbugs.gnu.org, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Thu, 2 Aug 2018 09:28:51 -0400
On 2 August 2018 at 09:08, Clément Pit-Claudel <cpitclaudel <at> gmail.com> wrote:

>> Usually the warning is due to the defvaralias call being performed after
>> the corresponding `defvar`s.
>
> Right. But why is that a problem?

The typical failure case goes like this, user does this:

(setq the-package-setting 'foo)
(require 'the-package)

And the-package.el does this:

(defvar the-package-real-setting 'bar)
;; Oops! User's setting of `foo' is overwritten here:
(defvaralias 'the-package-setting 'the-package-real-setting)

See Bug#31603 for a real life example.

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=31603




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Thu, 02 Aug 2018 14:38:02 GMT) Full text and rfc822 format available.

Message #51 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 5950 <at> debbugs.gnu.org, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Thu, 2 Aug 2018 10:37:25 -0400
On 2018-08-02 09:28, Noam Postavsky wrote:
> On 2 August 2018 at 09:08, Clément Pit-Claudel <cpitclaudel <at> gmail.com> wrote:
> 
>>> Usually the warning is due to the defvaralias call being performed after
>>> the corresponding `defvar`s.
>>
>> Right. But why is that a problem?
> 
> The typical failure case goes like this, user does this:
> 
> (setq the-package-setting 'foo)
> (require 'the-package)
> 
> And the-package.el does this:
> 
> (defvar the-package-real-setting 'bar)
> ;; Oops! User's setting of `foo' is overwritten here:
> (defvaralias 'the-package-setting 'the-package-real-setting)

Thanks.  Should the warning be disabled when both variables are already `defvar'd, then?

Clément.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Thu, 02 Aug 2018 17:04:02 GMT) Full text and rfc822 format available.

Message #54 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: 5950 <at> debbugs.gnu.org, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Thu, 02 Aug 2018 13:03:21 -0400
>> The typical failure case goes like this, user does this:
>> 
>> (setq the-package-setting 'foo)
>> (require 'the-package)
>> 
>> And the-package.el does this:
>> 
>> (defvar the-package-real-setting 'bar)
>> ;; Oops! User's setting of `foo' is overwritten here:
>> (defvaralias 'the-package-setting 'the-package-real-setting)
>
> Thanks.  Should the warning be disabled when both variables are
> already `defvar'd, then?

Why?  Replace `setq` with `defvar` in the above scenario and you have
the same problem.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Fri, 03 Aug 2018 03:34:02 GMT) Full text and rfc822 format available.

Message #57 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 5950 <at> debbugs.gnu.org, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Thu, 2 Aug 2018 23:33:39 -0400
On 2018-08-02 13:03, Stefan Monnier wrote:
>>> The typical failure case goes like this, user does this:
>>>
>>> (setq the-package-setting 'foo)
>>> (require 'the-package)
>>>
>>> And the-package.el does this:
>>>
>>> (defvar the-package-real-setting 'bar)
>>> ;; Oops! User's setting of `foo' is overwritten here:
>>> (defvaralias 'the-package-setting 'the-package-real-setting)
>>
>> Thanks.  Should the warning be disabled when both variables are
>> already `defvar'd, then?
> 
> Why?  Replace `setq` with `defvar` in the above scenario and you have
> the same problem.

Do you? I thought the problem was that you were overwriting a user setting… if you change the first setq into a defvar, where's the user setting that you're overwriting?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Fri, 03 Aug 2018 20:24:02 GMT) Full text and rfc822 format available.

Message #60 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: 5950 <at> debbugs.gnu.org, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Fri, 3 Aug 2018 16:23:22 -0400
On 2 August 2018 at 23:33, Clément Pit-Claudel <cpitclaudel <at> gmail.com> wrote:
> On 2018-08-02 13:03, Stefan Monnier wrote:
>>>> The typical failure case goes like this, user does this:
>>>>
>>>> (setq the-package-setting 'foo)
>>>> (require 'the-package)
>>>>
>>>> And the-package.el does this:
>>>>
>>>> (defvar the-package-real-setting 'bar)
>>>> ;; Oops! User's setting of `foo' is overwritten here:
>>>> (defvaralias 'the-package-setting 'the-package-real-setting)
>>>
>>> Thanks.  Should the warning be disabled when both variables are
>>> already `defvar'd, then?
>>
>> Why?  Replace `setq` with `defvar` in the above scenario and you have
>> the same problem.
>
> Do you? I thought the problem was that you were overwriting a user setting… if you change the first setq into a defvar, where's the user setting that you're overwriting?

If the user writes defvar instead of setq, it has the exact same
effect: they've set the-package-setting to foo, which will be
overwritten to bar, same as before.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Fri, 03 Aug 2018 21:01:02 GMT) Full text and rfc822 format available.

Message #63 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 5950 <at> debbugs.gnu.org, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Fri, 3 Aug 2018 17:00:33 -0400
On 2018-08-03 16:23, Noam Postavsky wrote:
> On 2 August 2018 at 23:33, Clément Pit-Claudel <cpitclaudel <at> gmail.com> wrote:
>> On 2018-08-02 13:03, Stefan Monnier wrote:
>>>>> The typical failure case goes like this, user does this:
>>>>>
>>>>> (setq the-package-setting 'foo)
>>>>> (require 'the-package)
>>>>>
>>>>> And the-package.el does this:
>>>>>
>>>>> (defvar the-package-real-setting 'bar)
>>>>> ;; Oops! User's setting of `foo' is overwritten here:
>>>>> (defvaralias 'the-package-setting 'the-package-real-setting)
>>>>
>>>> Thanks.  Should the warning be disabled when both variables are
>>>> already `defvar'd, then?
>>>
>>> Why?  Replace `setq` with `defvar` in the above scenario and you have
>>> the same problem.
>>
>> Do you? I thought the problem was that you were overwriting a user setting… if you change the first setq into a defvar, where's the user setting that you're overwriting?
> 
> If the user writes defvar instead of setq, it has the exact same
> effect: they've set the-package-setting to foo, which will be
> overwritten to bar, same as before.

Right, I understand that.  But why would a user write 'defvar' to set a user variable?
I guess I'm just a bit confused by the warning.  What's the proper way to resolve it?  Should I create the alias before loading flycheck?





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Fri, 03 Aug 2018 21:59:02 GMT) Full text and rfc822 format available.

Message #66 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: 5950 <at> debbugs.gnu.org, IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>,
 Noam Postavsky <npostavs <at> gmail.com>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Fri, 03 Aug 2018 17:58:06 -0400
> Do you?  I thought the problem was that you were overwriting a user setting…
> if you change the first setq into a defvar, where's the user setting that
> you're overwriting?

No, the problem is that you have 2 conflicting settings.
Whether one comes from the user doesn't really matter.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Fri, 03 Aug 2018 22:10:02 GMT) Full text and rfc822 format available.

Message #69 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>, 5950 <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Fri, 03 Aug 2018 18:09:12 -0400
Clément Pit-Claudel <cpitclaudel <at> gmail.com> writes:

> But why would a user write 'defvar' to set a user variable?

I don't know, why would a user write 'defvaralias' to set a user
variable?  They're users, completely unpredictable!  ;)

> What's the proper way to resolve it?  Should I create the alias before
> loading flycheck?

That would work too.  I made a couple of other suggestions in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=5950#42

Maybe we should add something like

    (defun defvaralias! (new-alias base-variable &optional docstring)
      (set new-alias (symbol-value base-variable))
      (defvaralias new-alias base-variable docstring))

Which you could use to tell Emacs not to care about losing the original
value of NEW-ALIAS.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#5950; Package emacs. (Fri, 03 Aug 2018 22:25:02 GMT) Full text and rfc822 format available.

Message #72 received at 5950 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>, 5950 <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#5950: defvaralias after defvar should be warned in runtime
Date: Fri, 3 Aug 2018 18:24:50 -0400
On 2018-08-03 18:09, Noam Postavsky wrote:
> That would work too.  I made a couple of other suggestions in
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=5950#42

Thanks, I missed that reply :) 
Adding setq before the defalias works fine :) Thanks a lot!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 01 Sep 2018 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 297 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.