type=: Compare &key parameters of function types.
authorStas Boukarev <stassats@gmail.com>
Sun, 31 Mar 2013 17:27:14 +0000 (21:27 +0400)
committerStas Boukarev <stassats@gmail.com>
Sun, 31 Mar 2013 17:27:14 +0000 (21:27 +0400)
Compare key parameters in type=-args, mostly so that deftransforms
with key arguments could be redefined at runtime.

src/code/late-type.lisp

index 63431b9..697b775 100644 (file)
                               :rest rest)
             exactp)))
 
+(defun compare-key-args (type1 type2)
+  (let ((keys1 (args-type-keywords type1))
+        (keys2 (args-type-keywords type2)))
+    (and (= (length keys1) (length keys2))
+         (eq (args-type-allowp type1)
+             (args-type-allowp type2))
+         (loop for key1 in keys1
+               for match = (find (key-info-name key1)
+                                 keys2 :key #'key-info-name)
+               always (and match
+                           (type= (key-info-type key1)
+                                  (key-info-type match)))))))
+
 (defun type=-args (type1 type2)
   (macrolet ((compare (comparator field)
                (let ((reader (symbolicate '#:args-type- field)))
      (and/type (and/type (compare type=-list required)
                          (compare type=-list optional))
                (if (or (args-type-keyp type1) (args-type-keyp type2))
-                   (values nil nil)
+                   (values (compare-key-args type1 type2) t)
                    (values t t))))))
 
 ;;; Do a union or intersection operation on types that might be values