<< Back to previous view

[CTYP-136] annotation for last does not leverage non-empty collections Created: 04/May/14  Updated: 31/May/14  Resolved: 31/May/14

Status: Closed
Project: core.typed
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Trivial
Reporter: Jake Goulding Assignee: Ambrose Bonnaire-Sergeant
Resolution: Completed Votes: 0
Labels: None

Attachments: File non-empty-last.diff    

 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)])))


 Comments   
Comment by Ambrose Bonnaire-Sergeant [ 31/May/14 12:51 PM ]

Merged.

Generated at Mon Nov 24 01:14:36 CST 2014 using JIRA 4.4#649-r158309.