Commit 613b4793 authored by Robert Goldman's avatar Robert Goldman
Browse files

Fix the modal logic of TYPE=.

Computing the correct return value of TYPE= requires combining the
primary and secondary returns of SUBTYPEP correctly.  Previously the
return value for combining (NIL NIL) and (T T) was incorrectly (NIL T)
instead of (NIL NIL).
parent d0e33584
Loading
Loading
Loading
Loading
+32 −19
Original line number Diff line number Diff line
@@ -124,14 +124,27 @@ and a secondary value that is true is the type equality could be reliably
determined: primary value of NIL and secondary value of T indicates that the
types are not equivalent."
  (multiple-value-bind (sub ok) (subtypep type1 type2)
    (cond ((and ok sub)
    (cond ((and ok sub) ; type1 is known to be a subtype of type 2
           ; so type= return values come from the second invocation of subtypep
           (subtypep type2 type1))
          ;; type1 is assuredly NOT a subtype of type2,
          ;; so assuredly type1 and type2 cannot be type=
          (ok
           (values nil ok))
           (values nil t))
          ;; our first result is uncertain ( ok == nil ) and it follows
          ;; from specification of SUBTYPEP that sub = ok = NIL
          (t
           (multiple-value-bind (sub ok) (subtypep type2 type1)
             (declare (ignore sub))
             (values nil ok))))))
           (assert (not sub))           ; is the implementation correct?
           (multiple-value-bind (sub2 ok2)
               (subtypep type2 type1)
             (if  (and (not sub2) ok2)  ; we KNOW type2 is not a subtype of type1
                  ;; so our results are certain...
                  (values nil t)
                  ;; otherwise, either type2 is surely a subtype of type1 (t t)
                  ;; or type2 is not a subtype of type1, but we don't
                  ;; know that for sure (nil nil)
                  ;; In either case our result is negative but unsure
                  (values nil nil)))))))

(define-modify-macro coercef (type-spec) coerce
  "Modify-macro for COERCE.")