(loop sum 2 count 1 repeat 3) => expansion error
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Low
|
Unassigned |
Bug Description
(loop sum 2 count 1 repeat 3)
[...first, just a warning, it may be ok...]
WARNING: unequal datatypes specified in different LOOP value accumulations
into NIL: FIXNUM and NUMBER
current LOOP context: COUNT 1 REPEAT.
[...but after that, expansion fails...]
The specified data type NUMBER is not a subtype of REAL.
current LOOP context: COUNT 1 REPEAT.
(signalled by LOOP-CHECK-
After reordering sum and count clauses, loop is expanded successfully:
(loop count 1 sum 2 repeat 3)
Notes:
1. Per CLHS 6.1.3 mixing sum, count, min and max is allowed.
2. Signalling a type-related error at macro-expansion time is obviously _bad_ when it's not the error of macro-function evaluation, but rather a result of some clever type checking. The whole loop form could be dead code, after all -- then it would be a conforming program, and I'd expect it to compile successfully.
3. Instead of examining subtype relations during loop body expansion, it would be both safer and easier to combine all type requirements for each collector with '(AND). The final result may be checked, if necessary, for being a subtype of NIL (i.e. the impossible, empty-domain type). SBCL is usually able to detect such type relations, e.g.: (SUBTYPEP '(AND FIXNUM CONS) NIL) => T T.
Changed in sbcl: | |
importance: | Undecided → Low |
status: | New → Triaged |
tags: | added: loop |
Changed in sbcl: | |
status: | Fix Committed → Fix Released |
In 8753b4d4169cc0f f6bc4bf42131ce1 492ba0ea83.