diff options
| author | Stefan Monnier | 2024-03-12 09:26:24 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2024-03-18 09:29:47 -0400 |
| commit | 706403f2aa3a306369a0150022da0cba1802ca2b (patch) | |
| tree | c2a2a7e1dc919efdead6ee36f1fb91e3f624c673 /test/src | |
| parent | 1a8b34a503e5af32851c1aac27a3f09e2345673b (diff) | |
| download | emacs-706403f2aa3a306369a0150022da0cba1802ca2b.tar.gz emacs-706403f2aa3a306369a0150022da0cba1802ca2b.zip | |
(cl-type-of): New function to return more precise types (bug#69739)
* src/data.c (Fcl_type_of): New function, extracted from `Ftype_of`.
Make it return more precise types for symbols, integers, and subrs.
(Ftype_of): Use it.
(syms_of_data): Define the corresponding new symbols and defsubr
the new function.
* doc/lispref/objects.texi (Type Predicates): Document it.
* src/comp.c (emit_limple_insn): Use `Fcl_type_of`.
* lisp/emacs-lisp/cl-preloaded.el (subr): Demote it to `atom`.
(subr-native-elisp, subr-primitive): Add `compiled-function` as
parent instead.
(special-form): New type.
* lisp/obsolete/eieio-core.el (cl--generic-struct-tag):
* lisp/emacs-lisp/cl-generic.el (cl--generic-typeof-generalizer):
Use `cl-type-of`.
cl--generic--unreachable-types): Update accordingly.
test/src/data-tests.el (data-tests--cl-type-of): New test.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/data-tests.el | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/src/data-tests.el b/test/src/data-tests.el index ad3b2071254..9d76c58224d 100644 --- a/test/src/data-tests.el +++ b/test/src/data-tests.el | |||
| @@ -838,4 +838,41 @@ comparing the subr with a much slower Lisp implementation." | |||
| 838 | (dolist (sym (list nil t 'xyzzy (make-symbol ""))) | 838 | (dolist (sym (list nil t 'xyzzy (make-symbol ""))) |
| 839 | (should (eq sym (bare-symbol (position-symbol sym 0))))))) | 839 | (should (eq sym (bare-symbol (position-symbol sym 0))))))) |
| 840 | 840 | ||
| 841 | (require 'cl-extra) ;For `cl--class-children'. | ||
| 842 | |||
| 843 | (ert-deftest data-tests--cl-type-of () | ||
| 844 | ;; Make sure that `cl-type-of' returns the most precise type. | ||
| 845 | ;; Note: This doesn't work for list/vector structs since those types | ||
| 846 | ;; are too difficult/unreliable to detect (so `cl-type-of' only says | ||
| 847 | ;; it's a `cons' or a `vector'). | ||
| 848 | (dolist (val (list -2 10 (expt 2 128) nil t 'car | ||
| 849 | (symbol-function 'car) | ||
| 850 | (symbol-function 'progn) | ||
| 851 | (position-symbol 'car 7))) | ||
| 852 | (let* ((type (cl-type-of val)) | ||
| 853 | (class (cl-find-class type)) | ||
| 854 | (alltypes (cl--class-allparents class)) | ||
| 855 | ;; FIXME: Our type DAG is affected by `symbols-with-pos-enabled'. | ||
| 856 | ;; (e.g. `symbolp' returns nil on a sympos if that var is nil). | ||
| 857 | (symbols-with-pos-enabled t)) | ||
| 858 | (dolist (parent alltypes) | ||
| 859 | (should (cl-typep val parent)) | ||
| 860 | (dolist (subtype (cl--class-children (cl-find-class parent))) | ||
| 861 | (unless (memq subtype alltypes) | ||
| 862 | (unless (memq subtype | ||
| 863 | ;; FIXME: Some types don't have any associated | ||
| 864 | ;; predicate, | ||
| 865 | '( font-spec font-entity font-object | ||
| 866 | finalizer condvar terminal | ||
| 867 | native-comp-unit interpreted-function | ||
| 868 | tree-sitter-compiled-query | ||
| 869 | tree-sitter-node tree-sitter-parser | ||
| 870 | ;; `functionp' also matches things of type | ||
| 871 | ;; `symbol' and `cons'. | ||
| 872 | ;; FIXME: `subr-primitive-p' also matches | ||
| 873 | ;; special-forms. | ||
| 874 | function subr-primitive)) | ||
| 875 | (should-not (cl-typep val subtype))))))))) | ||
| 876 | |||
| 877 | |||
| 841 | ;;; data-tests.el ends here | 878 | ;;; data-tests.el ends here |