+
+(assert
+ (equal
+ (let ((x 2d0))
+ (loop for d of-type double-float from 0d0 to 10d0 by x collect d))
+ '(0d0 2d0 4d0 6d0 8d0 10d0)))
+(assert
+ (equal
+ (let ((x 2d0))
+ (loop for d of-type double-float downfrom 10d0 to 0d0 by x collect d))
+ '(10d0 8d0 6d0 4d0 2d0 0d0)))
+
+(let ((fn (handler-case
+ (compile nil '(lambda ()
+ (declare (special x y))
+ (loop thereis (pop x) thereis (pop y))))
+ (warning (c) (error "Warned: ~S" c)))))
+ (let ((x (list nil nil 1))
+ (y (list nil 2 nil)))
+ (declare (special x y))
+ (assert (= (funcall fn) 2))))
+
+;;; Incorrect LIST type declaration, reported and patched by Teemu
+;;; Kalvas: end testing is done "as if by atom" so this is supposed
+;;; to work.
+(assert (equal '(1 2) (loop for (a . b) on '(1 2 . 3) collect a)))
+
+;;; Detection of duplicate bindings, reported by Bruno Haible for CMUCL.
+(multiple-value-bind (_ condition)
+ (ignore-errors
+ (macroexpand '(LOOP WITH A = 0 FOR A DOWNFROM 10 TO 0 DO (PRINT A))))
+ (declare (ignore _))
+ (assert (typep condition 'program-error)))
+
+;;; Loop variable with a range excluding 0, reported by Andras Simon.
+;;; (Used to signal an error during macroexpansion.)
+(assert (not (loop with foo of-type (single-float 1.0 2.0) = 1.5 do (return))))
+
+;;; 1.0.26.12 used to signal a bogus type error for this.
+(loop with x of-type (simple-vector 1) = (make-array '(1))
+ repeat 1
+ return x)
+
+(with-test (:name :bug-540186)
+ (let ((fun (compile nil `(lambda (x)
+ (loop for i from 0 below (length x)
+ for vec of-type vector = (aref x i)
+ collect vec)))))
+ (assert (equal '("foo" "bar")
+ (funcall fun
+ (vector "foo" "bar"))))))
+
+(with-test (:name :bug-lp613871)
+ (multiple-value-bind (function warnings-p failure-p)
+ (compile nil '(lambda () (loop with nil = 1 repeat 2 collect t)))
+ (assert (null warnings-p))
+ (assert (null failure-p))
+ (assert (equal '(t t) (funcall function))))
+ (multiple-value-bind (function warnings-p failure-p)
+ (compile nil '(lambda () (loop with nil repeat 2 collect t)))
+ (assert (null warnings-p))
+ (assert (null failure-p))
+ (assert (equal '(t t) (funcall function)))))
+
+(with-test (:name :bug-654220-regression)
+ (assert (= 32640 (loop for i to 255
+ sum i into sum of-type fixnum
+ finally (return sum)))))
+
+(with-test (:name :of-type-character-init)
+ ;; The intention here is to if we initialize C to NIL before iteration start
+ ;; by looking for tell-tale types such as (OR NULL CHARACTER). ...not the
+ ;; most robust test ever, no.
+ (let* ((fun (compile nil `(lambda (x)
+ (loop for c of-type character in x
+ collect (char-code c)))))
+ (consts (ctu:find-code-constants fun :type '(or symbol list))))
+ (assert (or (null consts) (equal 'character consts)))))