|
1103 | 1103 |
|
1104 | 1104 | IComparable
|
1105 | 1105 | (-compare [this other]
|
1106 |
| - (garray/defaultCompare (.valueOf this) (.valueOf other)))) |
| 1106 | + (if (instance? js/Date other) |
| 1107 | + (garray/defaultCompare (.valueOf this) (.valueOf other)) |
| 1108 | + (throw (js/Error. (str "Cannot compare " this " to " other)))))) |
1107 | 1109 |
|
1108 | 1110 | (extend-type number
|
1109 | 1111 | IEquiv
|
@@ -1935,13 +1937,18 @@ reduces them without incurring seq initialization"
|
1935 | 1937 |
|
1936 | 1938 | (nil? y) 1
|
1937 | 1939 |
|
1938 |
| - (identical? (type x) (type y)) |
1939 |
| - (if (implements? IComparable x) |
1940 |
| - (-compare ^not-native x y) |
1941 |
| - (garray/defaultCompare x y)) |
| 1940 | + (number? x) (if (number? y) |
| 1941 | + (garray/defaultCompare x y) |
| 1942 | + (throw (js/Error. (str "Cannot compare " x " to " y)))) |
| 1943 | + |
| 1944 | + (satisfies? IComparable x) |
| 1945 | + (-compare x y) |
1942 | 1946 |
|
1943 | 1947 | :else
|
1944 |
| - (throw (js/Error. "compare on non-nil objects of different types")))) |
| 1948 | + (if (and (or (string? x) (array? x) (true? x) (false? x)) |
| 1949 | + (identical? (type x) (type y))) |
| 1950 | + (garray/defaultCompare x y) |
| 1951 | + (throw (js/Error. (str "Cannot compare " x " to " y)))))) |
1945 | 1952 |
|
1946 | 1953 | (defn ^:private compare-indexed
|
1947 | 1954 | "Compare indexed collection."
|
@@ -8783,16 +8790,28 @@ reduces them without incurring seq initialization"
|
8783 | 8790 | ;; IComparable
|
8784 | 8791 | (extend-protocol IComparable
|
8785 | 8792 | Symbol
|
8786 |
| - (-compare [x y] (compare-symbols x y)) |
| 8793 | + (-compare [x y] |
| 8794 | + (if (symbol? y) |
| 8795 | + (compare-symbols x y) |
| 8796 | + (throw (js/Error. (str "Cannot compare " x " to " y))))) |
8787 | 8797 |
|
8788 | 8798 | Keyword
|
8789 |
| - (-compare [x y] (compare-keywords x y)) |
| 8799 | + (-compare [x y] |
| 8800 | + (if (keyword? y) |
| 8801 | + (compare-keywords x y) |
| 8802 | + (throw (js/Error. (str "Cannot compare " x " to " y))))) |
8790 | 8803 |
|
8791 | 8804 | Subvec
|
8792 |
| - (-compare [x y] (compare-indexed x y)) |
| 8805 | + (-compare [x y] |
| 8806 | + (if (vector? y) |
| 8807 | + (compare-indexed x y) |
| 8808 | + (throw (js/Error. (str "Cannot compare " x " to " y))))) |
8793 | 8809 |
|
8794 | 8810 | PersistentVector
|
8795 |
| - (-compare [x y] (compare-indexed x y))) |
| 8811 | + (-compare [x y] |
| 8812 | + (if (vector? y) |
| 8813 | + (compare-indexed x y) |
| 8814 | + (throw (js/Error. (str "Cannot compare " x " to " y)))))) |
8796 | 8815 |
|
8797 | 8816 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Reference Types ;;;;;;;;;;;;;;;;
|
8798 | 8817 |
|
|
0 commit comments