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.

Full log


View this message in rfc822 format

From: Glenn Morris <rgm <at> gnu.org>
To: IRIE Shinsuke <irieshinsuke <at> yahoo.co.jp>
Cc: 5950 <at> debbugs.gnu.org
Subject: 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)





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

Previous Next


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