[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: esup byte compile warnings
From: |
Stefan Monnier |
Subject: |
Re: esup byte compile warnings |
Date: |
Wed, 29 Jan 2020 09:32:18 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> Consider the following defun:
>
> (defun esup-total-exec-time (results)
> "Calculate the total execution time of RESULTS."
> (cl-loop for result in results
> sum (slot-value result 'exec-time) into total-exec-time
> finally return total-exec-time))
>
> This produces a waring:
>
> In esup-total-exec-time:
> esup.el:166:52: Warning: Unknown slot ‘exec-time’
This warning means that the bytecompiler has not seen any `defclass`
that defines a slot `exec-time`. Maybe it's perfectly normal (you know
that the object will indeed have an `exec-time` slot when that code will
be executed), e.g. because the object will be created in another file
which is not `require`d in this file, but without knowing more about
this slot it's hard to tell what's the best way to address the warning.
[...looking at https://github.com/jschaf/esup...]
Oh, I think it's because of
(let ((load-path (append load-path (list esup-load-path))))
(require 'esup-child))
which means that the `require` won't be executed by the byte-compiler
(because it's within a `let`). Either you should just drop this
`load-path` trickery (and push the responsability of `load-path`
manipulation to the code that byte-compiles the files, as usual), or you
may want to wrap this within an `eval-and-compile`.
> Looks like the reason is that the byte-compiler unable to match
> ‘result’ with the class declaration.
The compiler doesn't even try to infer types. It only checks that some
class somewhere has defined a slot of that name (that's good enough to
catch most typos).
Stefan
PS: While I'm here I noticed:
(eval-when-compile
(if (and (<= emacs-major-version 24)
(<= emacs-minor-version 3))
(require 'cl)
(require 'cl-lib)))
which makes no sense: those two libraries provide the same *kind* of
functionality, but under completely different names. The rest of the
code uses things like `cl-loop`, so you need to (require 'cl-lib)
because that's what the code uses. In Emacs<24.4, `cl-lib` will itself
load `cl` (because it uses it internally, but that's an implementation
detail).