<< Back to previous view

[CTYP-106] Else branch does not tighten scope to non-sequential Created: 19/Feb/14  Updated: 20/Jul/15  Resolved: 20/Jul/14

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

Type: Defect Priority: Major
Reporter: Cees van Kemenade Assignee: Ambrose Bonnaire-Sergeant
Resolution: Completed Votes: 0
Labels: None

Attachments: File failDerive1a.clj     File failDerive1.clj    


This error is related to the example longOptions.clj of CTYPE-102 and the derived hmap/big-options mentioned as CTYPE-99. I've prepared a new example to clearly show the issue.

The first function passes type-checking. However, it contains a redundant check on line 83 and a redundant base-case on line 85.

The second function does not pass the (check-ns) as it assumes that notifs can be a (seqable String). However, as this is the else-branch of line 112 (if (or (sequential? notifs) (seq? notifs) (vector notifs)) ... so the notifs can not be a (Seqable String) in this branch.

NOTE: core.typed does not know clojure.core/sequential? yet. Therefore the seq? and vector? tests are added too.

Comment by Ambrose Bonnaire-Sergeant [ 19/Feb/14 5:03 AM ]

Seqable doesn't extend Sequential, ISeq or IPersistentVector, so it's expected that this fails.

I suspect that the type for :st_notif is always an immutable clojure collection? If so, annotate :st_notif as (U (t/Coll String) String nil), and use (coll? notifs) as the predicate. Otherwise, try (not (string? notifs)) as the predicate.

Comment by Cees van Kemenade [ 19/Feb/14 2:18 PM ]

I tried to turn it into clojure.core.typed/Coll and that worked fine.
Thanks for the suggestion/solution!

Out of curiosity I tried as an alternative to check for (= (class notifs) clojure.lang.Seqable) as a second solution, but that did not solve the issue.
So I will stick to solution 1.

Comment by Ambrose Bonnaire-Sergeant [ 19/Feb/14 7:21 PM ]

= isn't useful for narrowing types, especially in the else branch. instance? and isa? would be more useful.

Comment by Cees van Kemenade [ 20/Feb/14 9:48 AM ]

Sorry, it was a typo from my side. I used (isa? ....) see line 166 of the attached fail failDerive1a.clj
This code triggers a type-error on line 171.

Comment by Ambrose Bonnaire-Sergeant [ 20/Jul/14 5:42 AM ]

I think this is resolved.

Generated at Sun Jan 21 11:04:00 CST 2018 using JIRA 4.4#649-r158309.