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

if-let on an hmap with an optional entry always expected to succeed

    Details

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

      Description

      How to reproduce:

      (t/cf (t/fn [m :- (t/HMap :optional {:a String} :complete? true)] (if-let [b (get m :a)] true)))
      

      Observed result:

      [[(t/HMap :optional {:a String} :complete? true) -> true :filters {:then tt, :else ff}] {:then tt, :else ff}]
      

      Expected result (pseudeocode):

      [(t/HMap :optional {:a String} :complete? true) -> (t/U nil true)]
      

      This is what you get if you replace the if-let above with if.

      Return type should be (t/Option true), as the if-let will result in a nil return if the :a key is not set on the map.

      Details:

      broz@macmicro:~$ grep try ~/.lein/profiles.clj
         [lein-try "0.4.3"]
      broz@macmicro:~$ lein try org.clojure/core.typed
      nREPL server started on port 52406 on host 127.0.0.1 - nrepl://127.0.0.1:52406
      REPL-y 0.3.5, nREPL 0.2.6
      Clojure 1.6.0
      Java HotSpot(TM) 64-Bit Server VM 1.8.0_40-b26
          Docs: (doc function-name-here)
                (find-doc "part-of-name-here")
        Source: (source function-name-here)
       Javadoc: (javadoc java-object-or-class-here)
          Exit: Control+D or (exit) or (quit)
       Results: Stored in vars *1, *2, *3, an exception in *e
      
      user=> (require ['clojure.core.typed :as 't])
      nil
      user=> (t/cf (t/fn [m :- (t/HMap :optional {:a String} :complete? true)] (if-let [b (get m :a)] true)))
      Initializing core.typed ...
      Building core.typed base environments ...
      Finished building base environments
      "Elapsed time: 14055.732654 msecs"
      core.typed initialized.
      [[(t/HMap :optional {:a String} :complete? true) -> true :filters {:then tt, :else ff}] {:then tt, :else ff}]
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: