type assertion too complex to check, unless inside another form

Bug #1879110 reported by Anticrisis
6
This bug affects 1 person
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-complex.lisp

(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/anticrisis/AppData/Local/Temp/slime40
; 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:NAMED-LAMBDA TEST-1
; (KEY ALIST-OF-STATUSES)
; (DECLARE (SB-C::TOP-LEVEL-FORM))
; (BLOCK TEST-1 (ALIST-FETCH KEY ALIST-OF-STATUSES)))
;
; 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-statuses))) r))

; 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-statuses)))

; compiling (DEFUN TEST-3 ...)

;; no notes printed

Revision history for this message
Anticrisis (anticrisis) wrote :

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.

Revision history for this message
Stas Boukarev (stassats) wrote :

It complaints because your type declarations do not restrict the number of values. Threading the result through VALUES or a variable makes it a single value.

I improved the error message, now it says

; in: DEFUN FOO
; (THE FIXNUM (FUNCALL X))
;
; note: Type assertion too complex to check:
; FIXNUM.
; It allows an unknown number of values, consider using
; (VALUES FIXNUM &OPTIONAL).
;

Changed in sbcl:
status: New → Fix Committed
Revision history for this message
Anticrisis (anticrisis) wrote :

Thank you for the quick action and for pointing me in the right direction. Every day I learn something!

Stas Boukarev (stassats)
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.