(def-alias PromoRecord (HMap :mandatory {:code String
                                         :deleted Boolean
                                         :siteId Long
                                         :startDate java.util.Date
                                         :used Boolean}
                             :optional  {:endDate java.util.Date}))
(def-alias PromoCode (U PromoRecord (Value :expired) nil))

(ann verify-promo-code [String Long Long -> (U PromoRecord String)])
(defn verify-promo-code
  "Given a promo code, a site ID and a user ID, return either a matching promo map
   or an i18n key (string) for expired / no match."
  [code user-id site-id]
  (let [promo (find-any-promo-code code (long user-id) (long site-id))]
    ;; this works:
    #_(cond (= :expired promo) "subscribe.message.expired.discountcode"
          (nil? promo)       "subscribe.message.invalid.discountcode"
          :default           promo)
    ;; this fails:
    (case :expired "subscribe.message.expired.discountcode"
          nil      "subscribe.message.invalid.discountcode"
          promo)
))

Errors from core.typed:

Type Error (worldsingles.promo-codes:84:5) Local binding promo expected type (U worldsingles.promo-codes/PromoRecord String), but actual type PromoCode
in: promo


Type Error (worldsingles.promo-codes:84:5) Type mismatch:

Expected: 	(U worldsingles.promo-codes/PromoRecord String)

Actual: 	nil
in: nil


Type Error (worldsingles.promo-codes:76) Type mismatch:

Expected: 	(U worldsingles.promo-codes/PromoRecord String)

Actual: 	(U worldsingles.promo-codes/PromoRecord nil (Value :expired))
in: (let* [promo (worldsingles.promo-codes/find-any-promo-code code (clojure.lang.RT/longCast user-id) (clojure.lang.RT/longCast site-id))] (let* [G__21094 :expired] (case* G__21094 1 1 (throw #) {1 #, 0 #} ...)))


Type Error (worldsingles.promo-codes:76) Type mismatch:

Expected: 	(Fn [java.lang.String java.lang.Long java.lang.Long -> (U java.lang.String PromoRecord)])

Actual: 	(Fn [java.lang.String java.lang.Long java.lang.Long -> (U worldsingles.promo-codes/PromoRecord nil (Value :expired))])
in: (fn* ([code user-id site-id] (let* [promo #] (let* # #))))


Type Error (worldsingles/promo_codes.clj:76:1) Type mismatch:

Expected: 	(Fn [java.lang.String java.lang.Long java.lang.Long -> (U java.lang.String PromoRecord)])

Actual: 	(Fn [java.lang.String java.lang.Long java.lang.Long -> (U worldsingles.promo-codes/PromoRecord nil (Value :expired))])
in: (def verify-promo-code (fn* ([code user-id site-id] (let* # #))))


Type Checker: Found 5 errors
Found errors
Subprocess failed

Did you know? CLOSE

  • There are keyboard shortcuts!
    • When Creating A Paste
      • ALT+P Toggle Private
      • CTRL+Enter Create Paste
      • ALT+W Toggle word wrap
    • When Viewing A Paste
      • ALT+G Go to a line
      • ALT+CTRL+E Edit the paste
      • ALT+R Show the raw code
  • There are URL options!
    • When Creating A Paste
      • ?lang=Javascript to default to javascript
    • When Viewing A Paste
      • #L-N Jump to line number N
?