(loop sum 2 count 1 repeat 3) => expansion error

Bug #798388 reported by Anton Kovalenko
6
This bug affects 1 person
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-DATA-TYPE called by LOOP-SUM-COLLECTION)

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.

Tags: loop
Changed in sbcl:
importance: Undecided → Low
status: New → Triaged
tags: added: loop
Revision history for this message
Stas Boukarev (stassats) wrote :

In 8753b4d4169cc0ff6bc4bf42131ce1492ba0ea83.

Changed in sbcl:
status: Triaged → 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.