Function: byte-compile-arglist-warn

byte-compile-arglist-warn is a byte-compiled function defined in bytecomp.el.gz.

Signature

(byte-compile-arglist-warn NAME ARGLIST MACROP)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
;; Warn if the function or macro is being redefined with a different
;; number of arguments.
(defun byte-compile-arglist-warn (name arglist macrop)
  ;; This is the first definition.  See if previous calls are compatible.
  (let ((calls (assq name byte-compile-unresolved-functions)))
    (when calls
      (when macrop
        (byte-compile-warn-x name "macro `%s' defined too late" name))
      (setq byte-compile-unresolved-functions
            (delq calls byte-compile-unresolved-functions))
      (let ((nums (delq t (cddr calls))))  ; Ignore higher-order uses.
        (when nums
          (when (and (symbolp name)
                     (eq (function-get name 'byte-optimizer)
                         'byte-compile-inline-expand))
            (byte-compile-warn-x
             name "defsubst `%s' was used before it was defined" name))
          (let ((sig (byte-compile-arglist-signature arglist))
                (min (apply #'min nums))
                (max (apply #'max nums)))
            (when (or (< min (car sig))
                      (and (cdr sig) (> max (cdr sig))))
              (byte-compile-warn-x
               name
               "%s being defined to take %s%s, but was previously called with %s"
               name
               (byte-compile-arglist-signature-string sig)
               (if (equal sig '(1 . 1)) " arg" " args")
               (byte-compile-arglist-signature-string (cons min max)))))))))
  (let* ((old (byte-compile-fdefinition name macrop))
         (initial (and macrop
                       (cdr (assq name
                                  byte-compile-initial-macro-environment)))))
    ;; Assumes an element of b-c-i-macro-env that is a symbol points
    ;; to a defined function.  (Bug#8646)
    (and initial (symbolp initial)
         (setq old (byte-compile-fdefinition initial nil)))
    (when (and old (not (eq old t)))
      (let ((sig1 (byte-compile--function-signature old))
            (sig2 (byte-compile-arglist-signature arglist)))
        (unless (byte-compile-arglist-signatures-congruent-p sig1 sig2)
          (byte-compile-warn-x
           name
           "%s %s used to take %s %s, now takes %s"
           (if macrop "macro" "function")
           name
           (byte-compile-arglist-signature-string sig1)
           (if (equal sig1 '(1 . 1)) "argument" "arguments")
           (byte-compile-arglist-signature-string sig2)))))))