Fix reading `#3(x).
authorStas Boukarev <stassats@gmail.com>
Fri, 4 Jan 2013 12:46:43 +0000 (16:46 +0400)
committerStas Boukarev <stassats@gmail.com>
Fri, 4 Jan 2013 12:46:43 +0000 (16:46 +0400)
Previously it returned #(x), while it should be #(x x x).

Fixes lp#1095918.

NEWS
src/code/sharpm.lisp
tests/reader.pure.lisp

diff --git a/NEWS b/NEWS
index 11036e5..666ead1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@
 changes relative to sbcl-1.1.3:
   * bug fix: very long (or infinite) constant lists in DOLIST do not result
     in very long compile times or heap exhaustion anymore. (lp#1095488)
+  * bug fix: `#3(1) is read as #(1 1 1), not as #(1). (lp#1095918)
 
 changes in sbcl-1.1.3 relative to sbcl-1.1.2:
   * enhancement: warnings about bad locale settings, LANG, LC_CTYPE, etc.
index 758114f..39c8e66 100644 (file)
 (defun sharp-left-paren (stream ignore length)
   (declare (ignore ignore) (special *backquote-count*))
   (let* ((list (read-list stream nil))
-         (listlength (handler-case (length list)
-                       (type-error
-                        (error)
-                        (declare (ignore error))
-                        (simple-reader-error stream
-                                             "improper list in #(): ~S"
-                                             list)))))
+         (list-length (handler-case (length list)
+                        (type-error ()
+                          (simple-reader-error stream
+                                               "Improper list in #(): ~S."
+                                               list)))))
     (declare (list list)
-             (fixnum listlength))
+             (fixnum list-length))
     (cond (*read-suppress* nil)
+          ((and length (> list-length length))
+           (simple-reader-error
+            stream
+            "Vector longer than the specified length: #~S~S."
+            length list))
           ((zerop *backquote-count*)
            (if length
-               (cond ((> listlength (the fixnum length))
-                      (simple-reader-error
-                       stream
-                       "vector longer than specified length: #~S~S"
-                       length list))
-                     (t
-                      (fill (the simple-vector
-                                 (replace (the simple-vector
-                                               (make-array length))
-                                          list))
-                            (car (last list))
-                            :start listlength)))
+               (fill (replace (make-array length) list)
+                     (car (last list))
+                     :start list-length)
                (coerce list 'vector)))
-          (t (cons *bq-vector-flag* list)))))
+          (t
+           (cons *bq-vector-flag*
+                 (if length
+                     (append list
+                             (make-list (- length list-length)
+                                        :initial-element (car (last list))))
+                     list))))))
 
 (defun sharp-star (stream ignore numarg)
   (declare (ignore ignore))
index 04d9dda..567235d 100644 (file)
   (with-timeout 10
     (assert (raises-error? (read-from-string "10e10000000000000000000")
                            sb-kernel:reader-impossible-number-error))))
+
+(with-test (:name :bug-1095918)
+  (assert (= (length `#3(1)) 3)))