diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-06-06 00:04:00 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-06-06 00:04:00 -0400 |
commit | 5ee4209f307fdf8cde9775539c9596d29edccd6d (patch) | |
tree | d8f806bf4fd46243a82fa04b3add723259743bc4 /lisp/emacs-lisp/eieio-core.el | |
parent | b90d2a6a63f1b7f73d2cb7e976148e8195fc5502 (diff) | |
download | emacs-5ee4209f307fdf8cde9775539c9596d29edccd6d.tar.gz emacs-5ee4209f307fdf8cde9775539c9596d29edccd6d.tar.bz2 emacs-5ee4209f307fdf8cde9775539c9596d29edccd6d.zip |
cl-typep: Emit warning when using a type not known to be a type
`cl-typep` has used a heuristic that if there's a `<foo>-p` function,
then <foo> can be used as a type. This made sense in the past where
most types were not officially declared to be (cl-)types, but nowadays
this just encourages abuses such as using `cl-typecase` with
"types" like `fbound`. It's also a problem for EIEIO objects, where
for historical reasons `<foo>-p` tests if the object is of type
exactly `<foo>` whereas (cl-typep OBJ <foo>) should instead test
if OBJ is a *subtype* of `<foo>`.
So we change `cl-typep` to emit a warning whenever this "-p" heuristic
is used, to discourage abuses, encourage the use of explicit
`cl-deftype` declarations, and try and detect some misuses of
`<foo>-p` for EIEIO objects.
* lisp/emacs-lisp/eieio.el (defclass): Define as type not only at
run-time but also for the current compilation unit.
* lisp/emacs-lisp/eieio-core.el (class, eieio-object): Define as types.
* lisp/emacs-lisp/cl-preloaded.el (cl-struct-define): Don't abuse the
"-p" heuristic.
* lisp/emacs-lisp/cl-macs.el (cl-deftype-satisfies):
Add entries for frames, windows, markers, and overlays.
(cl-typep): Emit a warning when using a predicate that is not known to
correspond to a type.
* lisp/files.el (file-relative-name): Fix error that can trigger if
there's an(other) error between loading `files.el` and loading
`minibuffer.el`.
Diffstat (limited to 'lisp/emacs-lisp/eieio-core.el')
-rw-r--r-- | lisp/emacs-lisp/eieio-core.el | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el index d687289b22f..d9864e6965d 100644 --- a/lisp/emacs-lisp/eieio-core.el +++ b/lisp/emacs-lisp/eieio-core.el @@ -137,6 +137,8 @@ Currently under control of this var: X can also be is a symbol." (eieio--class-p (if (symbolp x) (cl--find-class x) x))) +(cl-deftype class () `(satisfies class-p)) + (defun eieio--class-print-name (class) "Return a printed representation of CLASS." (format "#<class %s>" (eieio-class-name class))) @@ -165,6 +167,8 @@ Return nil if that option doesn't exist." (and (recordp obj) (eieio--class-p (eieio--object-class obj)))) +(cl-deftype eieio-object () `(satisfies eieio-object-p)) + (define-obsolete-function-alias 'object-p #'eieio-object-p "25.1") (defun class-abstract-p (class) |