plumatic / schema

Clojure(Script) library for declarative data description and validation
Other
2.41k stars 257 forks source link

isa schema not working correctly for keywords without hierarchy #369

Closed camsaul closed 8 years ago

camsaul commented 8 years ago

Not sure if I'm using this wrong, but it's not working as I'd expect.

(derive :type/Integer :type/Number) 
;; -> nil

(isa? :type/Integer :type/Number)
;; -> true

(s/validate (s/isa :type/Number) :type/Integer)
;; -> ExceptionInfo Value does not match schema: (throws? (isa? :type/Integer :type/Number))  schema.core/validator/fn--8446 (core.clj:155)

I can work around it using pred, so it's not a deal-breaker.

(s/validate (s/pred #(isa? % :type/Number)) :type/Integer) 
;; -> :type/Integer
w01fe commented 8 years ago

Yes, seems like this is a problem with isa and the default hierarchy -- thanks for the report. Since global-hierarchy is private, I guess the best solution is probably to avoid referencing it and passing the precondition directly into Isa. PR welcome!

On Wed, Sep 7, 2016 at 10:30 PM, Cam Saül notifications@github.com wrote:

Not sure if I'm using this wrong, but it's not working as I'd expect.

(derive :type/Integer :type/Number) ;; -> nil

(isa? :type/Integer :type/Number);; -> true

(s/validate (s/isa :type/Number) :type/Integer);; -> ExceptionInfo Value does not match schema: (throws? (isa? :type/Integer :type/Number)) schema.core/validator/fn--8446 (core.clj:155)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/plumatic/schema/issues/369, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIPphuoXxDKtTB3Q7aiWxyEMUWUHBJjks5qnx74gaJpZM4J3Utq .

camsaul commented 8 years ago

Makes sense. I'll try to submit a PR for this when I get a chance

w01fe commented 8 years ago

Great, thanks!