MAP: infer return type of mapping function

Bug #1720962 reported by Michał Herda on 2017-10-03
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

As per :

There is a function mentioned in the above blog post, the full body of which is:

(defun add-text-padding (str &key padding newline)
  "Add padding to text STR. Every line except for the first one, will be
prefixed with PADDING spaces. If NEWLINE is non-NIL, newline character will
be prepended to the text making it start on the next line with padding
applied to every single line."
  (let ((str (if newline
                 (concatenate 'string (string #\Newline) str)
    (with-output-to-string (s)
      (map 'string
           (lambda (x)
             (princ x s)
             (when (char= x #\Newline)
               (dotimes (i padding)
                 (princ #\Space s))))

The troublesome part is the (MAP 'STRING (LAMBDA (X) ...) STR) call. The anonymous function ends with a WHEN/DOTIMES call, which causes it to always return NIL. MAP 'STRING, in turn, requires that its function returns characters.

This information can be utilized by SBCL to emit a compile-time warning about mismatched types: the type exected by MAP and actual return type of the function.

Stas Boukarev (stassats) on 2017-10-03
Changed in sbcl:
status: New → Triaged
importance: Undecided → Wishlist
assignee: nobody → Stas Boukarev (stassats)
Stas Boukarev (stassats) wrote :

In da13f47cceaacafa6f4f60917032c2cdb22add5e.

Changed in sbcl:
status: Triaged → Fix Committed
assignee: Stas Boukarev (stassats) → nobody
Michał Herda (phoe-k) wrote :

That was fast! Thank you!

Stas Boukarev (stassats) on 2017-10-31
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers