type.lsp 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun May 29 08:25:46 2005
;;;; Contains: Tests of TYPE declarations

(in-package :cl-test)

;;; Also of implicit type declarations

(deftest type.1
  (let ((x 1))
    (declare (type (integer 0 1) x))
    (values
     x
     (setq x 0)
     (1+ x)))
  1 0 1)

(deftest type.2
  (let ((x 1))
    (declare (type (integer -1 1) x))
    (locally (declare (type (integer 0 2) x))
sds's avatar
sds committed
23 24 25 26
             (values
              x
              (setq x 0)
              (1+ x))))
27 28 29 30
  1 0 1)

(deftest type.3
  (loop for x in *mini-universe*
sds's avatar
sds committed
31 32 33 34 35 36 37
        for tp = (type-of x)
        for form = `(let ((y ',x))
                      (declare (type ,tp y))
                      y)
        for val = (eval form)
        unless (eql val x)
        collect (list x tp form val))
38 39 40 41
  nil)

(deftest type.4
  (loop for x in *mini-universe*
sds's avatar
sds committed
42 43 44 45 46 47 48
        for tp = (type-of x)
        for form = `(let ((y ',x))
                      (declare (,tp y))
                      y)
        for val = (eval form)
        unless (eql val x)
        collect (list x tp form val))
49 50 51 52
  nil)

(deftest type.5
  (loop for x in *mini-universe*
sds's avatar
sds committed
53 54 55 56 57 58 59
        for class = (class-of x)
        for form = `(let ((y ',x))
                      (declare (,class y))
                      y)
        for val = (eval form)
        unless (eql val x)
        collect (list x class form val))
60 61
  nil)

62 63 64
;;; Free TYPE declaration
;;; It should not apply to the occurence of X in the form
;;; whose value is being bound to Y.
65

66 67 68 69 70 71
(deftest type.6
  (let ((x 2))
    (let ((y (+ (decf x) 2)))
      (declare (type (integer 0 1) x))
      (values x y)))
  1 3)