Function: byte-compile-format-warn

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

Signature

(byte-compile-format-warn FORM)

Documentation

Warn if FORM is format-like with inconsistent args.

Applies if head of FORM is a symbol with non-nil property byte-compile-format-like and first arg is a constant string. Then check the number of format fields matches the number of extra args.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
(defun byte-compile-format-warn (form)
  "Warn if FORM is `format'-like with inconsistent args.
Applies if head of FORM is a symbol with non-nil property
`byte-compile-format-like' and first arg is a constant string.
Then check the number of format fields matches the number of
extra args."
  (when (and (symbolp (car form))
	     (stringp (nth 1 form))
	     (get (car form) 'byte-compile-format-like))
    (let* ((nargs (length (cddr form)))
           (nfields 0)
           (format-str (nth 1 form))
           (len (length format-str))
           (start 0))
      (while (and (< start len)
                  (string-match
                   (rx "%"
                       (? (group (+ digit)) "$")           ; field
                       (* (in "+ #0-"))                    ; flags
                       (* digit)                           ; width
                       (? "." (* digit))                   ; precision
                       (? (group (in "sdibBoxXefgcS%"))))  ; spec
                   format-str start))
        (let ((field (if (match-beginning 1)
                         (string-to-number (match-string 1 format-str))
                       (1+ nfields)))
              (spec (and (match-beginning 2)
                         (aref format-str (match-beginning 2)))))
          (setq start (match-end 0))
          (cond
           ((not spec)
            (byte-compile-warn-x
             form "Bad format sequence in call to `%s' at string offset %d"
             (car form) (match-beginning 0)))
           ((not (eq spec ?%))
            (setq nfields (max field nfields))))))
      (unless (= nargs nfields)
	(byte-compile-warn-x
         (car form) "`%s' called with %d argument%s to fill %d format field%s"
         (car form)
         nargs (if (= nargs 1) "" "s")
         nfields (if (= nfields 1) "" "s"))))))