Type checks elided unexpectedly
Describe the bug
Type checks are elided in some situations unexpectedly.
To Reproduce
Steps to reproduce the behavior: Consider the function
(defun foo (x y)
(declare (type (integer 0 30) x)
(type (integer 20 40) y))
(< x y))
Note that the types of x
and y
overlap so the compiler can't
statically determine the result. Then
* (foo 40 20)
Type-error in KERNEL::OBJECT-NOT-TYPE-ERROR-HANDLER: 40 is not of type (MOD 31)
[Condition of type TYPE-ERROR]
This is nice. But now consider
(defun foo2 (x y)
(declare (type (integer 0 10) x)
(type (integer 20 40) y))
(< x y))
Note that in this function, the values of x
are always less than the
values of y
. Hence the compiler can statically determine that the
result of foo2
is always T
. However,
* (foo2 10 20)
T
* (foo2 50 20)
T
The first result makes sense, but I was still expecting the second
invocation to produce a type error because 50 is not an (integer 0 10)
.
Adding a declaration to set (safety 3)
doesn't help. Adding an
optimize-interface
doesn't help either.
Expected behavior
Type checks are still expected.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: All
- Version: Found in snapshot-2021-7
Additional context
I tested this with 18c on Linux. The behavior is the same. @cshapiro tested with 18a. The behavior is the same. The conclusion we infer is that this was intended behavior, or this was not considered. Whatever the reason, it's been this way for a very long time.