【发布时间】:2016-04-30 00:51:28
【问题描述】:
假设:
- 我知道类型提示是关于性能优化的,而不是类型检查。我正在尝试解决性能优化何时无效。
假设我有以下代码:
(ns test.core)
(defrecord SquarePeg [width length])
(defrecord RoundHole [radius])
(def square-peg (SquarePeg. 5 50))
(defn insert-peg [^test.core.RoundHole peg]
(println "insert-peg inserted with: " peg))
(defn -main
"Insert a square peg in a round hole"
[& args]
(insert-peg square-peg))
当我运行它时,我得到:
insert-peg inserted with: #direct_linking_test.core.SquarePeg{:width 5, :length 50}
现在我希望这会有 一些 类型提示错误的指示,但事实并非如此。
现在我正在查看Clojure Compiler code - 我看到以下提示处理代码:
- hinted arg list
- emit static value from hinted fields
- get the class of the hinted field
- if hinted match method
但我没有看到它处理类型提示失败的地方。
我的问题是:为什么 Clojure 编译器不会为不正确的类型提示抛出错误?
【问题讨论】:
标签: clojure compiler-errors compiler-optimization type-hinting