]> git.eshelyaron.com Git - emacs.git/commitdiff
scope.el: Fix some errors
authorEshel Yaron <me@eshelyaron.com>
Sat, 29 Mar 2025 20:48:32 +0000 (21:48 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sat, 29 Mar 2025 20:48:32 +0000 (21:48 +0100)
lisp/emacs-lisp/scope.el

index 983ee140b08cf112262d1e723e033ce39841820e..88cf178ff521fdc0f6f53e230188b5d3f06924ff 100644 (file)
@@ -57,7 +57,7 @@ Optional argument LOCAL is a local context to extend."
 
 (defun scope-s (local sym)
   (let* ((beg (scope-sym-pos sym))
-         (bare (bare-symbol sym))
+         (bare (scope-sym-bare sym))
          (name (symbol-name bare))
          (len (length name))
          (scope--local local))
@@ -81,12 +81,13 @@ Optional argument LOCAL is a local context to extend."
   (if bindings
       (let* ((binding (ensure-list (car bindings)))
              (sym (car binding))
-             (bare (bare-symbol sym))
+             (bare (scope-sym-bare sym))
              (len (length (symbol-name bare)))
              (beg (scope-sym-pos sym)))
         (when beg (scope-report 'variable beg len beg))
         (scope-1 local0 (cadr binding))
-        (scope-let-1 local0 (scope-local-new bare beg local)
+        (scope-let-1 local0
+                     (if bare (scope-local-new bare beg local) local)
                      (cdr bindings) body))
     (scope-n local body)))
 
@@ -251,7 +252,7 @@ Optional argument LOCAL is a local context to extend."
           (scope-report 'function beg (length (symbol-name bare)) beg))
         (if (cdr exps)
             ;; def is (FUNC ARGLIST BODY...)
-            (scope-lambda local (car exps) (cdr exps))
+            (scope-cl-lambda local (car exps) (cdr exps))
           ;; def is (FUNC EXP)
           (scope-1 local (car exps)))
         (let ((scope-flet-alist (scope-local-new bare beg scope-flet-alist)))
@@ -308,7 +309,7 @@ Optional argument LOCAL is a local context to extend."
    ((consp arg) (scope-1 local arg))))
 
 (defun scope-declare-function (local fn _file arglist _fileonly)
-  (scope-defun local fn arglist nil))
+  (scope-defun local fn (when (listp arglist) arglist) nil))
 
 (defun scope-loop-for-and (local rest)
   (if (eq (scope-sym-bare (car rest)) 'and)
@@ -389,6 +390,8 @@ Optional argument LOCAL is a local context to extend."
 
 (defun scope-loop-for (local0 local vars rest)
   (if vars
+      ;; FIXME: var need not be a symbol, see
+      ;; `cl-macs-loop-destructure-cons' test in cl-macs-tests.el.
       (let* ((var (car (ensure-list vars)))
              (bare (bare-symbol var))
              (beg (scope-sym-pos var)))
@@ -561,7 +564,7 @@ Optional argument LOCAL is a local context to extend."
   (if (consp regexp)
       (let* ((head (car regexp))
              (bare (scope-sym-bare head)))
-        (when bare
+        (when (and bare (symbol-with-pos-p head))
           (scope-report 'rx-construct
                         (symbol-with-pos-pos head) (length (symbol-name bare))
                         (alist-get bare scope-rx-alist)))
@@ -578,7 +581,8 @@ Optional argument LOCAL is a local context to extend."
                         group submatch
                         group-n submatch-n))
           (scope-rx local (cdr regexp)))))
-    (when-let ((bare (scope-sym-bare regexp)))
+    (when-let (((symbol-with-pos-p regexp))
+               (bare (scope-sym-bare regexp)))
       (scope-report 'rx-construct
                     (symbol-with-pos-pos regexp) (length (symbol-name bare))
                     (alist-get bare scope-rx-alist)))))
@@ -1276,7 +1280,7 @@ a (possibly empty) list of safe macros.")
 (put 'provide 'scope-analyzer #'scope--analyze-featurep)
 (put 'require 'scope-analyzer #'scope--analyze-featurep)
 
-(scope-define-function-analyzer put-text-property (&optional _ _ prop val)
+(scope-define-function-analyzer put-text-property (&optional _ _ prop val _)
   (when (memq (scope-sym-bare (scope--unqoute prop)) '(mouse-face face))
     (when-let ((q (scope--unqoute val))) (scope-face q))))
 
@@ -1532,11 +1536,12 @@ a (possibly empty) list of safe macros.")
         (cond
          ((setq this (assq bare scope-flet-alist))
           (scope-report
-           'function (symbol-with-pos-pos f) (length (symbol-name bare)) this)
+           'function (symbol-with-pos-pos f) (length (symbol-name bare)) (cdr this))
           (scope-n local forms))
          ((setq this (assq bare scope-macrolet-alist))
-          (scope-report
-           'macro (symbol-with-pos-pos f) (length (symbol-name bare)) this)
+          (when (symbol-with-pos-p f)
+            (scope-report
+             'macro (symbol-with-pos-pos f) (length (symbol-name bare)) (cdr this)))
           ;; Local macros can be unsafe, so we do not expand them.
           ;; Hence we cannot interpret their arguments.
           )