core.typed

Support a Path Element for first/second/nth

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

What I tried:

(def-alias Statement
  (U
   '[':params String]
   '[':no-params]))

(ann unpack-vector [Statement -> Any])
(defn unpack-vector [stmt]
  (let [key (first stmt)]
    (if (= :params key)
      (let [param (second stmt)]
        (ann-form param String)))))

I expected this to type-check. Instead, I got:

Type Error (typed_mm/core.clj:14:9) Local binding param__#0 expected type java.lang.String, but actual type (t/Option (U (Value :params) (Value :no-params) String))
in: param
 
 
Type Error (typed_mm/core.clj:14:19) Type mismatch:
 
Expected: 	java.lang.String
 
Actual: 	(t/Option (U (Value :params) (Value :no-params) String))
in: param

I could understand core.typed thinking it could be `nil` if it looked at both members of the union, but it is very strange to me that it thinks the second item in the vector could be :params or :no-params, as those should only occur in the first position...

(With version 0.2.45-20140511.165157-12)

Activity

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: