;;;; Comparing enums, which type checked and then died in the backend. ;;;; ;;;; Types.is_comparable admits an enum, so the checker was stating an intent ;;;; emit never honoured: (= k :a) passed check and then raised ;;;; Failure("comparison on K") with no source location. An enum is an i32 at ;;;; run time, so all six operators lower to icmp. (defenum K [lo -1 mid 0 hi 1]) (defstruct S [k K]) (defn eq? [k K] bool (= k :mid)) (defn below? [k K] bool (< k :mid)) (defn main [] i32 ;; Equality, both ways round. (println (if (eq? :mid) "eq yes" "eq no")) (println (if (eq? :hi) "eq yes" "eq no")) ;; Ordering, and signed: lo is -1, so an unsigned compare would call it the ;; largest member and answer the other way. (println (if (below? :lo) "lo below mid" "lo not below mid")) (println (if (below? :hi) "hi below mid" "hi not below mid")) ;; And through a struct field, which is a different path to the same compare. (let [s (S {:k :hi})] (println (if (= (.k s) :hi) "field eq yes" "field eq no"))) 0)