2024 Clojure 状态调查!中分享您的想法。

欢迎!有关这个网站如何运作的更多信息,请参阅关于页面。

0 投票
core.typed
如何复现


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


观察结果


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


预期结果(伪代码)


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


这是如果您将上面的if-let替换为if所得到的结果。

返回类型应为(t/Option true),因为if-let将在map上没有设置:a键时返回nil。

细节


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
    Doc: (doc function-name-here)
          (find-doc "part-of-name-here")
  源: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    退出:Control+D 或 (exit) 或 (quit)
 结果:存储在 vars *1, *2, *3,异常在 *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}]

1 答案

0 投票
参考:https://clojure.atlassian.net/browse/CTYP-222 (由 alex+import 报告)
...