2024 年 Clojure 状况调查问卷中分享您的想法!

欢迎!有关这个平台运作方式的更多信息,请查阅关于页面。

0
规范

在使用 spec2 进行实验时,我发现以下行为像是一个错误。

(s/def ::s1 (s/schema {:a string?}))
=> :dev.fp.livingdocs.specs/s1
(s/def ::s2 (s/schema {:b string?}))
=> :dev.fp.livingdocs.specs/s2
(s/def ::s3 (s/schema {:c string?}))
=> :dev.fp.livingdocs.specs/s3

;; The following is unexpected (neseted unions)
(s/def ::u (s/union ::s1 (s/union ::s2 ::s3)))
Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1665$fn$G     (protocols.clj:20).
No implementation of method: :keyspecs* of protocol: #'clojure.alpha.spec.protocols/Schema found for class: clojure.lang.PersistentList
(s/def ::u (s/union (s/union ::s1 ::s2) ::s3))
Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1665$fn$G (protocols.clj:20).
No implementation of method: :keyspecs* of protocol: #'clojure.alpha.spec.protocols/Schema found for class: clojure.lang.PersistentList

;; if I try to pull out the nested union into a separate keyword, it starts working 
(s/def ::u' (s/union ::s1 ::s2))
=> :dev.fp.livingdocs.specs/u'
(s/def ::u (s/union ::u' ::s3))
=> :dev.fp.livingdocs.specs/u
(s/explain (s/select ::u [:a :c]) {:a "bdfd"})
{:a "bdfd"} - failed: (fn [m] (contains? m :c))

;; but also this
(s/form ::ld/typed)
=>
(clojure.alpha.spec/schema
 [{:name clojure.core/string?, :type clojure.core/string?}])
(s/form ::ldd/editable)
=>
(clojure.alpha.spec/schema
 [{:optional clojure.core/boolean?,
   :maxLength clojure.core/integer?,
   :plainText clojure.core/boolean?,
   :excluexcludeFromTextCount clojure.core/boolean?}])
 
(s/def ::service
  (s/or :single (s/select (s/union ::ld/typed ::ldd/editable) [:type :name :optional])
         :multiple (s/select (s/union :ld/typed ::ldd/editable) [:type :name :maxLength])))
Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1665$fn$G (protocols.clj:20).
No implementation of method: :keyspecs* of protocol: #'clojure.alpha.spec.protocols/Schema found for class: clojure.lang.PersistentList

在这两种情况下,s/union都出现在传给 spec 宏的形式中的嵌套位置。

1个回答

0

已被选中
 
最佳答案

谢谢,我相信我们已经为这个问题创建了一个工单。Spec 2 目前还在开发中,并非所有功能都正常工作。

顺便问一下,你们是否接受关于这个主题的补丁?(如果是的话,如何?)我可能发现了这个问题...
是的,您可以在这里找到流程: https://clojure.org/dev/dev#_becoming_a_contributor

编辑
谢谢!我已经提交了 https://clojure.atlassian.net/browse/CLJ-2613 作为对此问题的修复。

我还提交了 https://clojure.atlassian.net/browse/CLJ-2612,它修复了同一函数中的另一个问题。
谢谢,两个都已应用
...