core.typed

Else branch does not tighten scope to non-sequential

Details

  • Type: Defect Defect
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

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.

  1. failDerive1.clj
    19/Feb/14 1:48 AM
    6 kB
    Cees van Kemenade
  2. failDerive1a.clj
    20/Feb/14 9:50 AM
    9 kB
    Cees van Kemenade

Activity

Hide
Ambrose Bonnaire-Sergeant added a comment -

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.

Show
Ambrose Bonnaire-Sergeant added a comment - 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.
Hide
Cees van Kemenade added a comment -

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.

Show
Cees van Kemenade added a comment - 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.
Hide
Ambrose Bonnaire-Sergeant added a comment -

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

Show
Ambrose Bonnaire-Sergeant added a comment - = isn't useful for narrowing types, especially in the else branch. instance? and isa? would be more useful.
Hide
Cees van Kemenade added a comment -

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.

Show
Cees van Kemenade added a comment - 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.
Hide
Ambrose Bonnaire-Sergeant added a comment -

I think this is resolved.

Show
Ambrose Bonnaire-Sergeant added a comment - I think this is resolved.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: