[ea1220]: tests / clos-typechecking.impure.lisp Maximize Restore History

Download this file

clos-typechecking.impure.lisp    145 lines (139 with data), 5.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
(load "assertoid.lisp")
(defpackage "FOO"
(:use "CL" "ASSERTOID"))
(in-package "FOO")
(defclass foo ()
((slot :initarg :slot :type fixnum :accessor slot)))
(defclass foo/gf (sb-mop:standard-generic-function)
((slot/gf :initarg :slot/gf :type fixnum :accessor slot/gf))
(:metaclass sb-mop:funcallable-standard-class))
(defmethod succeed/sv ((x foo))
(setf (slot-value x 'slot) 1))
(defmethod fail/sv ((x foo))
(setf (slot-value x 'slot) t))
(defmethod succeed/acc ((x foo))
(setf (slot x) 1))
(defmethod fail/acc ((x foo))
(setf (slot x) t))
(defmethod succeed/sv/gf ((x foo/gf))
(setf (slot-value x 'slot/gf) 1))
(defmethod fail/sv/gf ((x foo/gf))
(setf (slot-value x 'slot/gf) t))
(defmethod succeed/acc/gf ((x foo/gf))
(setf (slot/gf x) 1))
(defmethod fail/acc/gf ((x foo/gf))
(setf (slot/gf x) t))
(defvar *t* t)
(defvar *one* 1)
;; evaluator
(eval '(setf (slot-value (make-instance 'foo) 'slot) 1))
(assert (raises-error? (eval '(setf (slot-value (make-instance 'foo) 'slot) t))
type-error))
(eval '(setf (slot (make-instance 'foo)) 1))
(assert (raises-error? (eval '(setf (slot (make-instance 'foo)) t))
type-error))
(eval '(succeed/sv (make-instance 'foo)))
(assert (raises-error? (eval '(fail/sv (make-instance 'foo)))
type-error))
(eval '(succeed/acc (make-instance 'foo)))
(assert (raises-error? (eval '(fail/acc (make-instance 'foo)))
type-error))
(eval '(make-instance 'foo :slot 1))
(assert (raises-error? (eval '(make-instance 'foo :slot t))
type-error))
(eval '(make-instance 'foo :slot *one*))
(assert (raises-error? (eval '(make-instance 'foo :slot *t*))
type-error))
;; evaluator/gf
(eval '(setf (slot-value (make-instance 'foo/gf) 'slot/gf) 1))
(assert (raises-error?
(eval '(setf (slot-value (make-instance 'foo/gf) 'slot/gf) t))
type-error))
(eval '(setf (slot/gf (make-instance 'foo/gf)) 1))
(assert (raises-error? (eval '(setf (slot/gf (make-instance 'foo/gf)) t))
type-error))
(eval '(succeed/sv/gf (make-instance 'foo/gf)))
#+nil ; funcallable standard instance slot-value access go through
; ACCESSOR-SLOT-VALUE because their classes are not
; STANDARD-CLASS-P.
(assert (raises-error? (eval '(fail/sv/gf (make-instance 'foo/gf)))
type-error))
(eval '(succeed/acc/gf (make-instance 'foo/gf)))
(assert (raises-error? (eval '(fail/acc/gf (make-instance 'foo/gf)))
type-error))
(eval '(make-instance 'foo/gf :slot/gf 1))
(assert (raises-error? (eval '(make-instance 'foo/gf :slot/gf t))
type-error))
(eval '(make-instance 'foo/gf :slot/gf *one*))
(assert (raises-error? (eval '(make-instance 'foo/gf :slot/gf *t*))
type-error))
;; compiler
(funcall (compile nil '(lambda ()
(setf (slot-value (make-instance 'foo) 'slot) 1))))
#+nil ; this one still fails goddamit.
(assert (raises-error?
(funcall
(compile nil '(lambda ()
(setf (slot-value (make-instance 'foo) 'slot) t))))
type-error))
(funcall (compile nil '(lambda () (setf (slot (make-instance 'foo)) 1))))
(assert (raises-error?
(funcall
(compile nil '(lambda () (setf (slot (make-instance 'foo)) t))))
type-error))
(funcall (compile nil '(lambda () (succeed/sv (make-instance 'foo)))))
(assert (raises-error?
(funcall (compile nil '(lambda () (fail/sv (make-instance 'foo)))))
type-error))
(funcall (compile nil '(lambda () (succeed/acc (make-instance 'foo)))))
(assert (raises-error?
(funcall (compile nil '(lambda () (fail/acc (make-instance 'foo)))))
type-error))
(funcall (compile nil '(lambda () (make-instance 'foo :slot 1))))
(assert (raises-error?
(funcall (compile nil '(lambda () (make-instance 'foo :slot t))))
type-error))
(funcall (compile nil '(lambda () (make-instance 'foo :slot *one*))))
(assert (raises-error?
(funcall (compile nil '(lambda () (make-instance 'foo :slot *t*))))
type-error))
;; compiler/gf
(funcall (compile nil
'(lambda ()
(setf (slot-value (make-instance 'foo/gf) 'slot/gf) 1))))
#+nil ; this one too
(assert (raises-error?
(funcall
(compile nil
'(lambda ()
(setf (slot-value (make-instance 'foo/gf) 'slot/gf) t))))
type-error))
(funcall (compile nil '(lambda () (setf (slot/gf (make-instance 'foo/gf)) 1))))
(assert (raises-error?
(funcall
(compile nil
'(lambda () (setf (slot/gf (make-instance 'foo/gf)) t))))
type-error))
(funcall (compile nil '(lambda () (succeed/sv/gf (make-instance 'foo/gf)))))
#+nil ; see above
(assert (raises-error?
(funcall (compile nil '(lambda ()
(fail/sv/gf (make-instance 'foo/gf)))))
type-error))
(funcall (compile nil '(lambda () (succeed/acc/gf (make-instance 'foo/gf)))))
(assert (raises-error?
(funcall (compile nil '(lambda ()
(fail/acc/gf (make-instance 'foo/gf)))))
type-error))
(funcall (compile nil '(lambda () (make-instance 'foo/gf :slot/gf 1))))
(assert (raises-error?
(funcall (compile nil '(lambda ()
(make-instance 'foo/gf :slot/gf t))))
type-error))
(funcall (compile nil '(lambda () (make-instance 'foo/gf :slot/gf *one*))))
(assert (raises-error?
(funcall (compile nil '(lambda ()
(make-instance 'foo/gf :slot/gf *t*))))
type-error))
;;;; success
(sb-ext:quit :unix-status 104)