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))
        nums sig min max)
    (when (and calls macrop)
      (byte-compile-warn "macro `%s' defined too late" name))
    (setq byte-compile-unresolved-functions
          (delq calls byte-compile-unresolved-functions))
    (setq calls (delq t calls))      ;Ignore higher-order uses of the function.
    (when (cddr calls)
      (when (and (symbolp name)
                 (eq (function-get name 'byte-optimizer)
                     'byte-compile-inline-expand))
        (byte-compile-warn "defsubst `%s' was used before it was defined"
                           name))
      (setq sig (byte-compile-arglist-signature arglist)
            nums (sort (copy-sequence (cddr calls)) (function <))
            min (car nums)
            max (car (nreverse nums)))
      (when (or (< min (car sig))
                (and (cdr sig) (> max (cdr sig))))
        (byte-compile-set-symbol-position name)
        (byte-compile-warn
         "%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-set-symbol-position name)
          (byte-compile-warn
           "%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)))))))