Uploaded image for project: 'core.typed'
  1. CTYP-274

Inferred type for {{defn}} and {{typed/fn}} with the same body are different

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects versions: 0.3.11
    • Fix versions: Backlog
    • Components: None
    • Labels:
      None

      Description

      Following code passes a type check as expected:

      (ann self-evaluating?
           [Any -> Boolean
            :filters {:then (is (U String Number) 0)
                      :else (! (U String Number) 0)}])
      (defn self-evaluating? [exp]
        (let [impl (typed/fn [x :- Any]
                     (or (number? x)
                         (string? x)))]
          (impl exp)))
      

      However, if I unwrap the typed/fn, it does not pass a type check:

      (ann self-evaluating?
           [Any -> Boolean
            :filters {:then (is (U String Number) 0)
                      :else (! (U String Number) 0)}])
      (defn self-evaluating? [exp]
        (or (number? exp)
            (string? exp)))
      
      Type Error (sicp/ch_4.clj:353:3) Expected result with filter {:then (is (U String Number) exp__#0), :else (! (U String Number) exp__#0)}, got filter {:then (& (| (is (U nil false) or__4238__auto____#0) (is Number exp__#0)) (| (! Number exp__#0) (! (U nil false) or__4238__auto____#0))), :else (& (| (is (U nil false) or__4238__auto____#0) (is Number exp__#0)) (| (! Number exp__#0) (! (U nil false) or__4238__auto____#0)))}
      in: (if or__4238__auto__ or__4238__auto__ (string? exp))
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: