core.typed

annotation for last does not leverage non-empty collections

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

I expected this to be all right:

(ann foo [(t/Coll t/AnyInteger) -> (U (Value :empty) t/AnyInteger)])
(defn foo [c]
  (if (seq c)
    (last c)
    :empty))

But I get this error:

Expected:       (U Long Integer BigInteger BigInt Byte Short (Value :empty))
Actual:         (U Long Integer BigInteger BigInt Byte Short (Value :empty) nil)

Reannotating last as this causes it to work:

(ann clojure.core/last
  (All [x]
       (Fn
        [(t/NonEmptySeqable x) -> x]
        [(t/Option (t/Seqable x)) -> (U nil x)])))

Activity

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: