with-redefs 是否需要多个参数?

hen*_*lle 4 clojurescript

我执行了以下代码(从真实用例中提取),并期望得到“Fake 2 a b”:

(defn real-func  
  ([a] (real-func a "S"))
  ([a b] (real-func a b "S")) 
  ([a b c] (println "Real " a b c)))

(defn fake-func 
  ([a b] (println "Fake 2" a b)))

(deftest blah-test
  (testing "blah blah"
    (with-redefs [real-func fake-func]  (real-func "a" "b"))))
Run Code Online (Sandbox Code Playgroud)

但我得到了一个错误: #object[TypeError TypeError: videra_web.effects.graphql_test.real_func.cljs$core$IFn$_invoke$arity$2 is not a function]

奇怪的是,如果我添加另一个数量(任何数量)fake-func它就可以了:例如

(defn fake-func 
  ([a b] (println "Fake 2" a b))
  ([a b c d e] (println "Fake 5" a b c d e))
)
Run Code Online (Sandbox Code Playgroud)

这看起来像是一个错误,还是有我不理解的语言功能?

Tho*_*ler 7

您可能正在运行编译的代码,:static-fns true这会阻止此类事情发生。

shadow-cljs如果您:compiler-options {:static-fns false}在构建配置中使用该集,则默认为 true 。