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

subtyping optional keywords in HMaps

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: 0.3.22
    • Fix versions: 0.3.23
    • Components: Clojure Checker
    • Labels:
      None

      Description

      I would expect all of these functions to be well typed, but I get an error only in the type of z-getter:

      (ns test.core
        (:require [clojure.core.typed :as t]))
      
      (t/defalias XYZMap
        (t/TFn [[x :variance :covariant :< Number]
                [y :variance :covariant :< Number]
                [z :variance :covariant :< Number]]
               (t/HMap :complete? true
                       :mandatory {:x x
                                   :y (t/Option y)}
                       :optional {:z z})))
      
      (t/defn x-getter
        [m :- (XYZMap Integer Integer Integer)] :- Integer
        (:x m))
      
      (t/defn y-getter
        [m :- (XYZMap Integer Integer Integer)] :- (t/Option Integer)
        (:y m))
      
      (t/defn z-getter
        [m :- (XYZMap Integer Integer Integer)] :- (t/Option Integer)
        (:z m))
      
      
      Type Error (test/core.clj:23:3) Type mismatch:
      
      Expected: 	(t/Option Integer)
      
      Actual: 	(t/U z nil)
      in: (:z m)
      
      ExceptionInfo Type Checker: Found 1 error  clojure.core/ex-info (core.clj:4593)
      

      Solution

      Type variables in optional HMap entries are not being substituted.

      Pull request: 100
      Commit: a62877
      Version: 0.3.23

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: