type-checking of &optional

Bug #1903932 reported by Douglas Katzman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

Types from FTYPE involving &optional are not respected.

(declaim (ftype (function (integer &optional pathname) t) what))
(defun what (x &optional (p *default-pathname-defaults*)) (list x p))
(what 1 2) => (1 2)

But adding a type declaration works:
(defun what (x &optional (p *default-pathname-defaults*))
  (declare (pathname p))
  (list x p))
(what 1 2)
  "The value 2 is not of type PATHNAME when binding P"

Keywords args are mostly right, but something about how code is generated requires insertion of (OR NULL) which leads to being less strict than is technically correct.

(declaim (ftype (function (integer &key (:p pathname)) t) whatk))
(defun whatk (x &key (p *default-pathname-defaults*)) (list x p))
(whatk 1 :p 2)
  "The value 2 is not of type (OR PATHNAME NULL) when binding P"
(whatk 1 :p nil) => (1 NIL) ; why is this allowed?

Revision history for this message
Douglas Katzman (dougk) wrote :
Changed in sbcl:
status: New → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.