Generator override doesn't work as expected on multi-specs.
Code below illustrates the problem.
{code:none}
(s/def ::obj-type #{:a :b})
(s/def ::base-obj (s/keys :req [::obj-type]))
(defmulti obj-type ::obj-type)
(defmethod obj-type :a [_]
::base-obj)
(defmethod obj-type :b [_]
::base-obj)
(s/def ::obj (s/multi-spec obj-type ::obj-type))
{code:none}
(gen/sample (s/gen ::obj {::obj-type #(gen/return :a)}))
In the example above the dispatch-fn *::obj-type* for the multimethod is given a generator override.
It is expected to return only colls of *{::obj-type :a}*
Actually it will also return *{::obj-type :b}*.
That is a generator cannot be used to constrain the set of dispatch-keys to sample from.
h2. Current method:
In the case of a multimethod a generator is constructed for every possible dispatch value.
One is then chosen randomly without paying any attention to overrides for the dispatch-fn(key).
h2. Patched method:
Commit available [here|
https://github.com/bonega/spec.alpha/commit/9cb42478b52eac275d496ec29669e2bf4b3e8e1f]
Patched version constructs generators for dispatch values exactly as original.
After that a check is made to see if there exists an override for the dispatch-fn.
If so a gen/bind is done using the override generator.
The bind function generates a value from the override generator.
That value is then used to lookup and return the correct multimethod generator.
[Test case|
https://pastebin.com/62ZT5Zfc]