type assertion too complex to check, unless inside another form
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
I have been using SBCL's compile-time type checking and have run into an odd but easily avoided compiler note. I'm reporting a bug because it's hard for me to see why the workaround actually eliminates the note, unless it's either 1) suppressing a problem that should be noted, or 2) working around an erroneous note.
Simple to reproduce. The function TEST-1 generates a note when compiled, but the other functions do not. (SLIME output is embedded in the listing below.)
;;;; type-too-
(in-package #:cl-user)
;; SBCL 2.0.4
(deftype flag () '(member :a :b :c))
(deftype status () '(or flag (cons flag t)))
(defun alist-fetch (key list)
(cdr (assoc key list)))
;; -------
(declaim (ftype (function (symbol list) (or null status)) test-1))
(defun test-1 (key alist-of-statuses)
(alist-fetch key alist-of-statuses))
; compiling (DEFUN TEST-1 ...)
; file: C:/Users/
; in: DEFUN TEST-1
; (DEFUN TEST-1 (KEY ALIST-OF-STATUSES) (ALIST-FETCH KEY ALIST-OF-STATUSES))
; --> PROGN SB-IMPL::%DEFUN SB-IMPL::%DEFUN SB-INT:NAMED-LAMBDA
; ==>
; #'(SB-INT:
; (KEY ALIST-OF-STATUSES)
; (DECLARE (SB-C::
; (BLOCK TEST-1 (ALIST-FETCH KEY ALIST-OF-
;
; note: type assertion too complex to check:
; (VALUES &OPTIONAL (OR (MEMBER :C :B :A NIL) (CONS (MEMBER :A :B :C) T)) &REST T).
;
; compilation unit finished
; printed 1 note
;; -------
(declaim (ftype (function (symbol list) (or null status)) test-2))
(defun test-2 (key alist-of-statuses)
(let ((r (alist-fetch key alist-of-
; compiling (DEFUN TEST-2 ...)
;; no notes printed
;; -------
(declaim (ftype (function (symbol list) (or null status)) test-3))
(defun test-3 (key alist-of-statuses)
(values (alist-fetch key alist-of-
; compiling (DEFUN TEST-3 ...)
;; no notes printed
Changed in sbcl: | |
status: | Fix Committed → Fix Released |
Of course, seconds after submitting what I thought I had thoroughly reviewed, I noted that my report is incomplete: If the function ALIST-FETCH is also annotated with a function ftype declaration, all three TEST functions compile without a note. But I don't think that explains the variations in the original test case.