Does not report type violations for code that would have been reported as unreachable

Bug #1909883 reported by Michael Fiano on 2021-01-03
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Undecided
Unassigned

Bug Description

The following does not report that 42 is not of type string:

(declaim (ftype (function () string) foo))
(defun foo ()
  (declare (optimize speed))
  (loop)
  42)

The derived type is NIL, so this is expected. However it does report a DCE for:

(declaim (ftype (function () string) foo))
(defun foo ()
  (declare (optimize speed))
  (loop)
  '(42))

At first I thought SBCL was omitting the return type checking for simple literal types, but:

(declaim (ftype (function () string) foo))
(defun foo ()
  (declare (optimize speed))
  (loop :while t
        :do (when (= (random 10) 1) (loop-finish)))
  42)

reports the type problem as expected.

I think there are two issues here:

1) not reporting unreachable code
2) not reporting type violations for code that would have been reported as unreachable

This violates the principle of least surprise because SBCL in most cases warns about unreachable code.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers