COERCE tries too hard, does wrong thing anyway
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Undecided
|
Douglas Katzman |
Bug Description
In its effort to cover as many cases as possible, the COERCE transform in safety 0 may produce an incorrect expansion which is accompanied by a style-warning.
(defun f1 (x)
(declare (optimize (safety 0)))
(coerce x '(or (array (signed-byte 8) (*)) (array (unsigned-byte 8) (*)))))
-> (LAMBDA (X TYPE)
(DECLARE (IGNORABLE TYPE X))
(THE (OR (VECTOR (UNSIGNED-BYTE 8)) (VECTOR (SIGNED-BYTE 8)))
(IF (TYPEP X '(OR (VECTOR (UNSIGNED-BYTE 8)) (VECTOR (SIGNED-BYTE 8))))
X
But MAKE-ARRAY on the element-type as determined by the transform is a valid call, making an array that is not of a type matching the union type.
* (make-array 1 :element-type '(integer -128 255))
#<(SIMPLE-ARRAY (SIGNED-BYTE 16) (1)) {10016A370F}>
This code probably should not work. And if that's so, the compiler should give up and let it defer to the full COERCE function, which says that it shouldn't work:
* (coerce '(1 2 3) '(or (array (signed-byte 8) (*)) (array (unsigned-byte 8) (*))))
(OR (VECTOR (SIGNED-BYTE 8))
(VECTOR (UNSIGNED-BYTE 8))) is too hairy for sequence functions.
Changed in sbcl: | |
assignee: | nobody → Douglas Katzman (dougk) |
status: | New → Fix Committed |
Changed in sbcl: | |
status: | Fix Committed → Fix Released |