1.0.13.45: close the fd before deleting / moving files on CLOSE :ABORT T
[sbcl/simd.git] / tests / type.impure.lisp
blobe1e0b738133ee0b5f323da11777875a1f27362df
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; While most of SBCL is derived from the CMU CL system, the test
5 ;;;; files (like this one) were written from scratch after the fork
6 ;;;; from CMU CL.
7 ;;;;
8 ;;;; This software is in the public domain and is provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
10 ;;;; more information.
12 (load "assertoid.lisp")
13 (use-package "ASSERTOID")
14 (use-package "TEST-UTIL")
16 (defmacro assert-nil-nil (expr)
17 `(assert (equal '(nil nil) (multiple-value-list ,expr))))
18 (defmacro assert-nil-t (expr)
19 `(assert (equal '(nil t) (multiple-value-list ,expr))))
20 (defmacro assert-t-t (expr)
21 `(assert (equal '(t t) (multiple-value-list ,expr))))
23 (defmacro assert-t-t-or-uncertain (expr)
24 `(assert (let ((list (multiple-value-list ,expr)))
25 (or (equal '(nil nil) list)
26 (equal '(t t) list)))))
28 (let ((types '(character
29 integer fixnum (integer 0 10)
30 single-float (single-float -1.0 1.0) (single-float 0.1)
31 (real 4 8) (real -1 7) (real 2 11)
32 null symbol keyword
33 (member #\a #\b #\c) (member 1 #\a) (member 3.0 3.3)
34 (member #\a #\c #\d #\f) (integer -1 1)
35 unsigned-byte
36 (rational -1 7) (rational -2 4)
37 ratio
38 )))
39 (dolist (i types)
40 (format t "type I=~S~%" i)
41 (dolist (j types)
42 (format t " type J=~S~%" j)
43 (assert (subtypep i `(or ,i ,j)))
44 (assert (subtypep i `(or ,j ,i)))
45 (assert (subtypep i `(or ,i ,i ,j)))
46 (assert (subtypep i `(or ,j ,i)))
47 (dolist (k types)
48 (format t " type K=~S~%" k)
49 (assert (subtypep `(or ,i ,j) `(or ,i ,j ,k)))
50 (assert (subtypep `(or ,i ,j) `(or ,k ,j ,i)))))))
52 ;;; gotchas that can come up in handling subtypeness as "X is a
53 ;;; subtype of Y if each of the elements of X is a subtype of Y"
54 (let ((subtypep-values (multiple-value-list
55 (subtypep '(single-float -1.0 1.0)
56 '(or (real -100.0 0.0)
57 (single-float 0.0 100.0))))))
58 (assert (member subtypep-values
59 '(;; The system isn't expected to
60 ;; understand the subtype relationship.
61 (nil nil)
62 ;; But if it does, that'd be neat.
63 (t t)
64 ;; (And any other return would be wrong.)
66 :test #'equal)))
68 (defun type-evidently-= (x y)
69 (and (subtypep x y)
70 (subtypep y x)))
72 (assert (subtypep 'single-float 'float))
74 (assert (type-evidently-= '(integer 0 10) '(or (integer 0 5) (integer 4 10))))
76 ;;; Bug 50(c,d): numeric types with empty ranges should be NIL
77 (assert (type-evidently-= 'nil '(integer (0) (0))))
78 (assert (type-evidently-= 'nil '(rational (0) (0))))
79 (assert (type-evidently-= 'nil '(float (0.0) (0.0))))
81 ;;; sbcl-0.6.10 did (UPGRADED-ARRAY-ELEMENT-TYPE 'SOME-UNDEF-TYPE)=>T
82 ;;; and (UPGRADED-COMPLEX-PART-TYPE 'SOME-UNDEF-TYPE)=>T.
83 (assert (raises-error? (upgraded-array-element-type 'some-undef-type)))
84 (assert (eql (upgraded-array-element-type t) t))
85 (assert (raises-error? (upgraded-complex-part-type 'some-undef-type)))
86 (assert (subtypep (upgraded-complex-part-type 'fixnum) 'real))
88 ;;; Do reasonable things with undefined types, and with compound types
89 ;;; built from undefined types.
90 ;;;
91 ;;; part I: TYPEP
92 (assert (typep #(11) '(simple-array t 1)))
93 (assert (typep #(11) '(simple-array (or integer symbol) 1)))
94 (assert (raises-error? (typep #(11) '(simple-array undef-type 1))))
95 (assert (not (typep 11 '(simple-array undef-type 1))))
96 ;;; part II: SUBTYPEP
98 (assert (subtypep '(vector some-undef-type) 'vector))
99 (assert (not (subtypep '(vector some-undef-type) 'integer)))
100 (assert-nil-nil (subtypep 'utype-1 'utype-2))
101 (assert-nil-nil (subtypep '(vector utype-1) '(vector utype-2)))
102 (assert-nil-nil (subtypep '(vector utype-1) '(vector t)))
103 (assert-nil-nil (subtypep '(vector t) '(vector utype-2)))
105 ;;; ANSI specifically disallows bare AND and OR symbols as type specs.
106 (assert (raises-error? (typep 11 'and)))
107 (assert (raises-error? (typep 11 'or)))
108 (assert (raises-error? (typep 11 'member)))
109 (assert (raises-error? (typep 11 'values)))
110 (assert (raises-error? (typep 11 'eql)))
111 (assert (raises-error? (typep 11 'satisfies)))
112 (assert (raises-error? (typep 11 'not)))
113 ;;; and while it doesn't specifically disallow illegal compound
114 ;;; specifiers from the CL package, we don't have any.
115 (assert (raises-error? (subtypep 'fixnum '(fixnum 1))))
116 (assert (raises-error? (subtypep 'class '(list))))
117 (assert (raises-error? (subtypep 'foo '(ratio 1/2 3/2))))
118 (assert (raises-error? (subtypep 'character '(character 10))))
119 #+nil ; doesn't yet work on PCL-derived internal types
120 (assert (raises-error? (subtypep 'lisp '(class))))
121 #+nil
122 (assert (raises-error? (subtypep 'bar '(method number number))))
124 ;;; Of course empty lists of subtypes are still OK.
125 (assert (typep 11 '(and)))
126 (assert (not (typep 11 '(or))))
128 ;;; bug 12: type system didn't grok nontrivial intersections
129 (assert (subtypep '(and symbol (satisfies keywordp)) 'symbol))
130 (assert (not (subtypep '(and symbol (satisfies keywordp)) 'null)))
131 (assert (subtypep 'keyword 'symbol))
132 (assert (not (subtypep 'symbol 'keyword)))
133 (assert (subtypep 'ratio 'real))
134 (assert (subtypep 'ratio 'number))
136 ;;; bug 50.g: Smarten up hairy type specifiers slightly. We may wish
137 ;;; to revisit this, perhaps by implementing a COMPLEMENT type
138 ;;; (analogous to UNION and INTERSECTION) to take the logic out of the
139 ;;; HAIRY domain.
140 (assert-nil-t (subtypep 'atom 'cons))
141 (assert-nil-t (subtypep 'cons 'atom))
142 ;;; These two are desireable but not necessary for ANSI conformance;
143 ;;; maintenance work on other parts of the system broke them in
144 ;;; sbcl-0.7.13.11 -- CSR
145 #+nil
146 (assert-nil-t (subtypep '(not list) 'cons))
147 #+nil
148 (assert-nil-t (subtypep '(not float) 'single-float))
149 (assert-t-t (subtypep '(not atom) 'cons))
150 (assert-t-t (subtypep 'cons '(not atom)))
151 ;;; ANSI requires that SUBTYPEP relationships among built-in primitive
152 ;;; types never be uncertain, i.e. never return NIL as second value.
153 ;;; Prior to about sbcl-0.7.2.6, ATOM caused a lot of problems here
154 ;;; (because it's a negation type, implemented as a HAIRY-TYPE, and
155 ;;; CMU CL's HAIRY-TYPE logic punted a lot).
156 (assert-t-t (subtypep 'integer 'atom))
157 (assert-t-t (subtypep 'function 'atom))
158 (assert-nil-t (subtypep 'list 'atom))
159 (assert-nil-t (subtypep 'atom 'integer))
160 (assert-nil-t (subtypep 'atom 'function))
161 (assert-nil-t (subtypep 'atom 'list))
162 ;;; ATOM is equivalent to (NOT CONS):
163 (assert-t-t (subtypep 'integer '(not cons)))
164 (assert-nil-t (subtypep 'list '(not cons)))
165 (assert-nil-t (subtypep '(not cons) 'integer))
166 (assert-nil-t (subtypep '(not cons) 'list))
167 ;;; And we'd better check that all the named types are right. (We also
168 ;;; do some more tests on ATOM here, since once CSR experimented with
169 ;;; making it a named type.)
170 (assert-t-t (subtypep 'nil 'nil))
171 (assert-t-t (subtypep 'nil 'atom))
172 (assert-t-t (subtypep 'nil 't))
173 (assert-nil-t (subtypep 'atom 'nil))
174 (assert-t-t (subtypep 'atom 'atom))
175 (assert-t-t (subtypep 'atom 't))
176 (assert-nil-t (subtypep 't 'nil))
177 (assert-nil-t (subtypep 't 'atom))
178 (assert-t-t (subtypep 't 't))
179 ;;; Also, LIST is now somewhat special, in that (NOT LIST) should be
180 ;;; recognized as a subtype of ATOM:
181 (assert-t-t (subtypep '(not list) 'atom))
182 (assert-nil-t (subtypep 'atom '(not list)))
183 ;;; These used to fail, because when the two arguments to subtypep are
184 ;;; of different specifier-type types (e.g. HAIRY and UNION), there
185 ;;; are two applicable type methods -- in this case
186 ;;; HAIRY-COMPLEX-SUBTYPEP-ARG1-TYPE-METHOD and
187 ;;; UNION-COMPLEX-SUBTYPEP-ARG2-TYPE-METHOD. Both of these exist, but
188 ;;; [!%]INVOKE-TYPE-METHOD aren't smart enough to know that if one of
189 ;;; them returns NIL, NIL (indicating uncertainty) it should try the
190 ;;; other. However, as of sbcl-0.7.2.6 or so, CALL-NEXT-METHOD-ish
191 ;;; logic in those type methods fixed it.
192 (assert-nil-t (subtypep '(not cons) 'list))
193 (assert-nil-t (subtypep '(not single-float) 'float))
194 ;;; Somewhere along the line (probably when adding CALL-NEXT-METHOD-ish
195 ;;; logic in SUBTYPEP type methods) we fixed bug 58 too:
196 (assert-t-t (subtypep '(and zilch integer) 'zilch))
197 (assert-t-t (subtypep '(and integer zilch) 'zilch))
199 ;;; Bug 84: SB-KERNEL:CSUBTYPEP was a bit enthusiastic at
200 ;;; special-casing calls to subtypep involving *EMPTY-TYPE*,
201 ;;; corresponding to the NIL type-specifier; we were bogusly returning
202 ;;; NIL, T (indicating surety) for the following:
203 (assert-nil-nil (subtypep '(satisfies some-undefined-fun) 'nil))
205 ;;; It turns out that, as of sbcl-0.7.2, we require to be able to
206 ;;; detect this to compile src/compiler/node.lisp (and in particular,
207 ;;; the definition of the component structure). Since it's a sensible
208 ;;; thing to want anyway, let's test for it here:
209 (assert-t-t (subtypep '(or some-undefined-type (member :no-ir2-yet :dead))
210 '(or some-undefined-type (member :no-ir2-yet :dead))))
211 ;;; BUG 158 (failure to compile loops with vector references and
212 ;;; increments of greater than 1) was a symptom of type system
213 ;;; uncertainty, to wit:
214 (assert-t-t (subtypep '(and (mod 536870911) (or (integer 0 0) (integer 2 536870912)))
215 '(mod 536870911))) ; aka SB-INT:INDEX.
216 ;;; floating point types can be tricky.
217 (assert-t-t (subtypep '(member 0.0) '(single-float 0.0 0.0)))
218 (assert-t-t (subtypep '(member -0.0) '(single-float 0.0 0.0)))
219 (assert-t-t (subtypep '(member 0.0) '(single-float -0.0 0.0)))
220 (assert-t-t (subtypep '(member -0.0) '(single-float 0.0 -0.0)))
221 (assert-t-t (subtypep '(member 0.0d0) '(double-float 0.0d0 0.0d0)))
222 (assert-t-t (subtypep '(member -0.0d0) '(double-float 0.0d0 0.0d0)))
223 (assert-t-t (subtypep '(member 0.0d0) '(double-float -0.0d0 0.0d0)))
224 (assert-t-t (subtypep '(member -0.0d0) '(double-float 0.0d0 -0.0d0)))
226 (assert-nil-t (subtypep '(single-float 0.0 0.0) '(member 0.0)))
227 (assert-nil-t (subtypep '(single-float 0.0 0.0) '(member -0.0)))
228 (assert-nil-t (subtypep '(single-float -0.0 0.0) '(member 0.0)))
229 (assert-nil-t (subtypep '(single-float 0.0 -0.0) '(member -0.0)))
230 (assert-nil-t (subtypep '(double-float 0.0d0 0.0d0) '(member 0.0d0)))
231 (assert-nil-t (subtypep '(double-float 0.0d0 0.0d0) '(member -0.0d0)))
232 (assert-nil-t (subtypep '(double-float -0.0d0 0.0d0) '(member 0.0d0)))
233 (assert-nil-t (subtypep '(double-float 0.0d0 -0.0d0) '(member -0.0d0)))
235 (assert-t-t (subtypep '(member 0.0 -0.0) '(single-float 0.0 0.0)))
236 (assert-t-t (subtypep '(single-float 0.0 0.0) '(member 0.0 -0.0)))
237 (assert-t-t (subtypep '(member 0.0d0 -0.0d0) '(double-float 0.0d0 0.0d0)))
238 (assert-t-t (subtypep '(double-float 0.0d0 0.0d0) '(member 0.0d0 -0.0d0)))
240 (assert-t-t (subtypep '(not (single-float 0.0 0.0)) '(not (member 0.0))))
241 (assert-t-t (subtypep '(not (double-float 0.0d0 0.0d0)) '(not (member 0.0d0))))
243 (assert-t-t (subtypep '(float -0.0) '(float 0.0)))
244 (assert-t-t (subtypep '(float 0.0) '(float -0.0)))
245 (assert-t-t (subtypep '(float (0.0)) '(float (-0.0))))
246 (assert-t-t (subtypep '(float (-0.0)) '(float (0.0))))
248 ;;;; Douglas Thomas Crosher rewrote the CMU CL type test system to
249 ;;;; allow inline type tests for CONDITIONs and STANDARD-OBJECTs, and
250 ;;;; generally be nicer, and Martin Atzmueller ported the patches.
251 ;;;; They look nice but they're nontrivial enough that it's not
252 ;;;; obvious from inspection that everything is OK. Let's make sure
253 ;;;; that things still basically work.
255 ;; structure type tests setup
256 (defstruct structure-foo1)
257 (defstruct (structure-foo2 (:include structure-foo1))
259 (defstruct (structure-foo3 (:include structure-foo2)))
260 (defstruct (structure-foo4 (:include structure-foo3))
261 y z)
263 ;; structure-class tests setup
264 (defclass structure-class-foo1 () () (:metaclass cl:structure-class))
265 (defclass structure-class-foo2 (structure-class-foo1)
266 () (:metaclass cl:structure-class))
267 (defclass structure-class-foo3 (structure-class-foo2)
268 () (:metaclass cl:structure-class))
269 (defclass structure-class-foo4 (structure-class-foo3)
270 () (:metaclass cl:structure-class))
272 ;; standard-class tests setup
273 (defclass standard-class-foo1 () () (:metaclass cl:standard-class))
274 (defclass standard-class-foo2 (standard-class-foo1)
275 () (:metaclass cl:standard-class))
276 (defclass standard-class-foo3 (standard-class-foo2)
277 () (:metaclass cl:standard-class))
278 (defclass standard-class-foo4 (standard-class-foo3)
279 () (:metaclass cl:standard-class))
281 ;; condition tests setup
282 (define-condition condition-foo1 (condition) ())
283 (define-condition condition-foo2 (condition-foo1) ())
284 (define-condition condition-foo3 (condition-foo2) ())
285 (define-condition condition-foo4 (condition-foo3) ())
287 ;;; inline type tests
288 (format t "~&/setting up *TESTS-OF-INLINE-TYPE-TESTS*~%")
289 (defparameter *tests-of-inline-type-tests*
290 '(progn
292 ;; structure type tests
293 (assert (typep (make-structure-foo3) 'structure-foo2))
294 (assert (not (typep (make-structure-foo1) 'structure-foo4)))
295 (assert (typep (nth-value 1
296 (ignore-errors (structure-foo2-x
297 (make-structure-foo1))))
298 'type-error))
299 (assert (null (ignore-errors
300 (setf (structure-foo2-x (make-structure-foo1)) 11))))
302 ;; structure-class tests
303 (assert (typep (make-instance 'structure-class-foo3)
304 'structure-class-foo2))
305 (assert (not (typep (make-instance 'structure-class-foo1)
306 'structure-class-foo4)))
307 (assert (null (ignore-errors
308 (setf (slot-value (make-instance 'structure-class-foo1)
310 11))))
312 ;; standard-class tests
313 (assert (typep (make-instance 'standard-class-foo3)
314 'standard-class-foo2))
315 (assert (not (typep (make-instance 'standard-class-foo1)
316 'standard-class-foo4)))
317 (assert (null (ignore-errors
318 (setf (slot-value (make-instance 'standard-class-foo1) 'x)
319 11))))
321 ;; condition tests
322 (assert (typep (make-condition 'condition-foo3)
323 'condition-foo2))
324 (assert (not (typep (make-condition 'condition-foo1)
325 'condition-foo4)))
326 (assert (null (ignore-errors
327 (setf (slot-value (make-condition 'condition-foo1) 'x)
328 11))))
329 (assert (subtypep 'error 't))
330 (assert (subtypep 'simple-condition 'condition))
331 (assert (subtypep 'simple-error 'simple-condition))
332 (assert (subtypep 'simple-error 'error))
333 (assert (not (subtypep 'condition 'simple-condition)))
334 (assert (not (subtypep 'error 'simple-error)))
335 (assert (eq (car (sb-pcl:class-direct-superclasses
336 (find-class 'simple-condition)))
337 (find-class 'condition)))
339 #+nil ; doesn't look like a good test
340 (let ((subclasses (mapcar #'find-class
341 '(simple-type-error
342 simple-error
343 simple-warning
344 sb-int:simple-file-error
345 sb-int:simple-style-warning))))
346 (assert (null (set-difference
347 (sb-pcl:class-direct-subclasses (find-class
348 'simple-condition))
349 subclasses))))
351 ;; precedence lists
352 (assert (equal (sb-pcl:class-precedence-list
353 (find-class 'simple-condition))
354 (mapcar #'find-class '(simple-condition
355 condition
356 sb-pcl::slot-object
357 t))))
359 ;; stream classes
360 (assert (equal (sb-pcl:class-direct-superclasses (find-class
361 'fundamental-stream))
362 (mapcar #'find-class '(standard-object stream))))
363 (assert (null (set-difference
364 (sb-pcl:class-direct-subclasses (find-class
365 'fundamental-stream))
366 (mapcar #'find-class '(fundamental-binary-stream
367 fundamental-character-stream
368 fundamental-output-stream
369 fundamental-input-stream)))))
370 (assert (equal (sb-pcl:class-precedence-list (find-class
371 'fundamental-stream))
372 (mapcar #'find-class '(fundamental-stream
373 standard-object
374 sb-pcl::slot-object
375 stream
376 t))))
377 (assert (equal (sb-pcl:class-precedence-list (find-class
378 'fundamental-stream))
379 (mapcar #'find-class '(fundamental-stream
380 standard-object
381 sb-pcl::slot-object stream
382 t))))
383 (assert (subtypep (find-class 'stream) (find-class t)))
384 (assert (subtypep (find-class 'fundamental-stream) 'stream))
385 (assert (not (subtypep 'stream 'fundamental-stream)))))
386 ;;; Test under the interpreter.
387 (eval *tests-of-inline-type-tests*)
388 (format t "~&/done with interpreted *TESTS-OF-INLINE-TYPE-TESTS*~%")
389 ;;; Test under the compiler.
390 (defun tests-of-inline-type-tests ()
391 #.*tests-of-inline-type-tests*)
392 (tests-of-inline-type-tests)
393 (format t "~&/done with compiled (TESTS-OF-INLINE-TYPE-TESTS)~%")
395 ;;; Redefinition of classes should alter the type hierarchy (BUG 140):
396 (defclass superclass () ())
397 (defclass maybe-subclass () ())
398 (assert-nil-t (subtypep 'maybe-subclass 'superclass))
399 (defclass maybe-subclass (superclass) ())
400 (assert-t-t (subtypep 'maybe-subclass 'superclass))
401 (defclass maybe-subclass () ())
402 (assert-nil-t (subtypep 'maybe-subclass 'superclass))
404 ;;; Prior to sbcl-0.7.6.27, there was some confusion in ARRAY types
405 ;;; specialized on some as-yet-undefined type which would cause this
406 ;;; program to fail (bugs #123 and #165). Verify that it doesn't.
407 (defun foo (x)
408 (declare (type (vector bar) x))
409 (aref x 1))
410 (deftype bar () 'single-float)
411 (assert (eql (foo (make-array 3 :element-type 'bar :initial-element 0.0f0))
412 0.0f0))
414 ;;; bug 260a
415 (assert-t-t
416 (let* ((s (gensym))
417 (t1 (sb-kernel:specifier-type s)))
418 (eval `(defstruct ,s))
419 (sb-kernel:type= t1 (sb-kernel:specifier-type s))))
421 ;;; bug found by PFD's random subtypep tester
422 (let ((t1 '(cons rational (cons (not rational) (cons integer t))))
423 (t2 '(not (cons (integer 0 1) (cons single-float long-float)))))
424 (assert-t-t (subtypep t1 t2))
425 (assert-nil-t (subtypep t2 t1))
426 (assert-t-t (subtypep `(not ,t2) `(not ,t1)))
427 (assert-nil-t (subtypep `(not ,t1) `(not ,t2))))
429 ;;; not easily visible to user code, but this used to be very
430 ;;; confusing.
431 (with-test (:name (:ctor :typep-function))
432 (assert (eval '(typep (sb-pcl::ensure-ctor
433 (list 'sb-pcl::ctor (gensym)) nil nil nil)
434 'function))))
435 (with-test (:name (:ctor :functionp))
436 (assert (functionp (sb-pcl::ensure-ctor
437 (list 'sb-pcl::ctor (gensym)) nil nil nil))))
439 ;;; from PFD ansi-tests
440 (let ((t1 '(cons (cons (cons (real -744833699 -744833699) cons)
441 (integer -234496 215373))
442 integer))
443 (t2 '(cons (cons (cons integer integer)
444 (integer -234496 215373))
445 t)))
446 (assert (null (values (subtypep `(not ,t2) `(not ,t1))))))
448 (defstruct misc-629a)
449 (defclass misc-629b () ())
450 (defclass misc-629c () () (:metaclass sb-mop:funcallable-standard-class))
452 (assert (typep (make-misc-629a) 'sb-kernel:instance))
453 (assert-t-t (subtypep `(member ,(make-misc-629a)) 'sb-kernel:instance))
454 (assert-nil-t (subtypep `(and (member ,(make-misc-629a)) sb-kernel:instance)
455 nil))
456 (let ((misc-629a (make-misc-629a)))
457 (assert-t-t (subtypep `(member ,misc-629a)
458 `(and (member ,misc-629a) sb-kernel:instance)))
459 (assert-t-t (subtypep `(and (member ,misc-629a)
460 sb-kernel:funcallable-instance)
461 nil)))
463 (assert (typep (make-instance 'misc-629b) 'sb-kernel:instance))
464 (assert-t-t (subtypep `(member ,(make-instance 'misc-629b))
465 'sb-kernel:instance))
466 (assert-nil-t (subtypep `(and (member ,(make-instance 'misc-629b))
467 sb-kernel:instance)
468 nil))
469 (let ((misc-629b (make-instance 'misc-629b)))
470 (assert-t-t (subtypep `(member ,misc-629b)
471 `(and (member ,misc-629b) sb-kernel:instance)))
472 (assert-t-t (subtypep `(and (member ,misc-629b)
473 sb-kernel:funcallable-instance)
474 nil)))
476 (assert (typep (make-instance 'misc-629c) 'sb-kernel:funcallable-instance))
477 (assert-t-t (subtypep `(member ,(make-instance 'misc-629c))
478 'sb-kernel:funcallable-instance))
479 (assert-nil-t (subtypep `(and (member ,(make-instance 'misc-629c))
480 sb-kernel:funcallable-instance)
481 nil))
482 (let ((misc-629c (make-instance 'misc-629c)))
483 (assert-t-t (subtypep `(member ,misc-629c)
484 `(and (member ,misc-629c)
485 sb-kernel:funcallable-instance)))
486 (assert-t-t (subtypep `(and (member ,misc-629c)
487 sb-kernel:instance)
488 nil)))
490 ;;; this was broken during the FINALIZE-INHERITANCE rearrangement; the
491 ;;; MAKE-INSTANCE finalizes the superclass, thus invalidating the
492 ;;; subclass, so SUBTYPEP must be prepared to deal with
493 (defclass ansi-tests-defclass1 () ())
494 (defclass ansi-tests-defclass3 (ansi-tests-defclass1) ())
495 (make-instance 'ansi-tests-defclass1)
496 (assert-t-t (subtypep 'ansi-tests-defclass3 'standard-object))
498 ;;; so was this
499 (let ((class (eval '(defclass to-be-type-ofed () ()))))
500 (setf (find-class 'to-be-type-ofed) nil)
501 (assert (eq (type-of (make-instance class)) class)))
503 ;;; accuracy of CONS :SIMPLE-TYPE-=
504 (deftype goldbach-1 () '(satisfies even-and-greater-then-two-p))
505 (deftype goldbach-2 () ' (satisfies sum-of-two-primes-p))
507 (multiple-value-bind (ok win)
508 (sb-kernel:type= (sb-kernel:specifier-type '(cons goldbach1 integer))
509 (sb-kernel:specifier-type '(cons goldbach1 integer)))
510 (assert ok)
511 (assert win))
513 ;; See FIXME in type method for CONS :SIMPLE-TYPE-=
514 #+nil
515 (multiple-value-bind (ok win)
516 (sb-kernel:type= (sb-kernel:specifier-type '(cons goldbach1 integer))
517 (sb-kernel:specifier-type '(cons goldbach1 single-float)))
518 (assert (not ok))
519 (assert win))
521 (multiple-value-bind (ok win)
522 (sb-kernel:type= (sb-kernel:specifier-type '(cons goldbach1 integer))
523 (sb-kernel:specifier-type '(cons goldbach2 single-float)))
524 (assert (not ok))
525 (assert (not win)))
527 ;;; precise unions of array types (was bug 306a)
528 (defun bug-306-a (x)
529 (declare (optimize speed)
530 (type (or (array cons) (array vector)) x))
531 (elt (aref x 0) 0))
532 (assert (= 0 (bug-306-a #((0)))))
534 ;;; FUNCALLABLE-INSTANCE is a subtype of function.
535 (assert-t-t (subtypep '(and pathname function) nil))
536 (assert-t-t (subtypep '(and pathname sb-kernel:funcallable-instance) nil))
537 (assert (not (subtypep '(and stream function) nil)))
538 (assert (not (subtypep '(and stream sb-kernel:funcallable-instance) nil)))
539 (assert (not (subtypep '(and function standard-object) nil)))
540 (assert (not (subtypep '(and sb-kernel:funcallable-instance standard-object) nil)))
542 ;;; also, intersections of classes with INSTANCE should not be too
543 ;;; general
544 (assert (not (typep #'print-object '(and standard-object sb-kernel:instance))))
545 (assert (not (subtypep 'standard-object '(and standard-object sb-kernel:instance))))
547 (assert-t-t
548 (subtypep '(or simple-array simple-string) '(or simple-string simple-array)))
549 (assert-t-t
550 (subtypep '(or simple-string simple-array) '(or simple-array simple-string)))
551 (assert-t-t
552 (subtypep '(or fixnum simple-string end-of-file parse-error fixnum vector)
553 '(or fixnum vector end-of-file parse-error fixnum simple-string)))
555 #+sb-eval
556 (assert-t-t
557 (subtypep '(and function (not compiled-function)
558 (not sb-eval:interpreted-function))
559 nil))
561 ;;; weakening of union type checks
562 (defun weaken-union-1 (x)
563 (declare (optimize speed))
564 (car x))
565 (multiple-value-bind (res err)
566 (ignore-errors (weaken-union-1 "askdjhasdkj"))
567 (assert (not res))
568 (assert (typep err 'type-error)))
569 (defun weaken-union-2 (x)
570 (declare (optimize speed)
571 (type (or cons fixnum) x))
572 (etypecase x
573 (fixnum x)
574 (cons
575 (setf (car x) 3)
576 x)))
577 (multiple-value-bind (res err)
578 (ignore-errors (weaken-union-2 "asdkahsdkhj"))
579 (assert (not res))
580 (assert (typep err 'type-error))
581 (assert (or (equal '(or cons fixnum) (type-error-expected-type err))
582 (equal '(or fixnum cons) (type-error-expected-type err)))))
584 ;;; success