FILTER-DOLIST-DECLARATIONS braindamaged
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
The DOLIST macro expands to code which binds its step variable to NIL while evaluating an optional result form.
For that to work, it "cleverly" deletes type declarations provided they look *exactly* like (DECLARE ({IGNORE|TYPE} ...)) so that if a declaration possibly pertains to the step variable, it can't cause an error. Ironically this can manifest as an error in two ways:
1. FILTER-
* (dolist (s '("HI" "THERE") 'foo) (declare (string s)) (print (length s)))
; in: DOLIST (S '("HI" "THERE") 'FOO)
...
; caught WARNING:
; Constant NIL conflicts with its asserted type STRING.
...
2
5
debugger invoked on a SIMPLE-TYPE-ERROR:
...
so if it is correct to bind 's' at all [which I believe it is not], the fix is to recognize symbols as type names when they are.
Of course, if the declaration were instead (declare (type string s)), it would be deleted, and thus not fail.
2. But CLtL2 says (p. 219)
"X3J13 voted ... * The scope of a declaration always includes the body forms, as well as any "stepper" or "result" forms"
so it's incorrect to remove type declarations that don't pertain specifically to bindings made in this dolist. [Discussion of pervasive/
A fix which is most correct is also easiest: don't bind 's' in the result form, and don't weed out declarations. Cracauer agrees.
For the record:
* bash-3.2$ sbcl --version
SBCL 1.0.54.0-185b926
What do you mean "don't bind 's' in the result form"? The standard explicitly states "At the time result-form is processed, var is bound to nil."