+;;; Return forms to test that OBJ has the element-type specified by
+;;; type specified by TYPE, where STYPE is the type we have checked
+;;; against (which is the same but for dimensions and element type).
+(defun test-array-element-type (obj type stype)
+ (declare (type array-type type stype))
+ (let ((obj `(truly-the ,(type-specifier stype) ,obj))
+ (eltype (array-type-specialized-element-type type)))
+ (unless (type= eltype (array-type-specialized-element-type stype))
+ (with-unique-names (data)
+ `((do ((,data ,obj (%array-data-vector ,data)))
+ ((not (array-header-p ,data))
+ ;; KLUDGE: this isn't in fact maximally efficient,
+ ;; because though we know that DATA is a (SIMPLE-ARRAY *
+ ;; (*)), we will still check to see if the lowtag is
+ ;; appropriate.
+ (typep ,data
+ '(simple-array ,(type-specifier eltype) (*))))))))))
+