ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.23k stars 141 forks source link

SRFI 231: Fix flatten-vector->list #976

Closed gambiteer closed 6 months ago

gambiteer commented 6 months ago

Check for nonempty vector:

diff --git a/lib/srfi/231/transforms.scm b/lib/srfi/231/transforms.scm
index 20d8c688..0741bf6f 100644
--- a/lib/srfi/231/transforms.scm
+++ b/lib/srfi/231/transforms.scm
@@ -576,7 +576,7 @@
 (define (flatten-vector->list vec d)
   (cond
    ((not (vector? vec)) '())
-   ((and (positive? d) (vector? (vector-ref vec 0)))
+   ((and (positive? d) (positive? (vector-length vec)) (vector? (vector-ref vec 0)))
     (append-map (lambda (x) (flatten-vector->list x (- d 1)))
                 (vector->list vec)))
    (else (vector->list vec))))

This patch and the previous one allows to compute the following correctly:

(array-every equal? (vector*->array 2 '#()) (make-array (make-interval '#(0 0)) (lambda () (error))))