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

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

bug#8140: 24.0.50; wrong compilation warning


From: Stefan Monnier
Subject: bug#8140: 24.0.50; wrong compilation warning
Date: Mon, 28 Feb 2011 11:24:27 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

severity 8140 wishlist
thanks

> the following code:

> (if (eval-when-compile (eq 'w32 window-system))
>     (defun foo () ...) ; woe32 definition
>     (defun foo () ...)) ; unix definition

> (defun bar () ... (foo) ... )

> results in this byte-compilation warning:

> In end of data:
> lib.el:2029:1:Warning: the function `foo' is not known to be defined.

> I think the warning is wrong because it should be pretty easy for the
> compiler to see that `foo' is always defined.

That's right.  It's fairly easy to write a code that can decide which
functions are known to exist and which aren't.  OTOH given the existing
bytecomp.el structure, it's not that easy to make it understand that in
the above code `foo' will always be defined.  Of course, maybe there's
a clever way to do it, but at least for now it seems unlikely to happen.

So until it does happen I recommend you use

  (defalias 'foo
    (if blabla
        (lambda () ...)
      (lambda () ...)))

which makes it more obvious to the byte-compiler that `foo' will indeed
always be defined.  The above form works well for single-function
definitions, but it's not as nice when doing

   (cond
    (toto
     (defun foo1 ...)
     (defun foo2 ...)
     (defun foo3 ...))
    (t
     (defun foo1 ...)
     (defun foo2 ...)
     (defun foo3 ...)))

so it would indeed be good to teach the byte-compiler how to figure
these things out.


        Stefan





reply via email to

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