-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use clj-kondo :seqable
for :+
, :*
, and :?
not {:op :rest}
#952
Use clj-kondo :seqable
for :+
, :*
, and :?
not {:op :rest}
#952
Conversation
Update clj-kondo type generation. `{:op :rest}` should be used only for varargs. ``` This can be used to match remaining arguments in vararg signatures. https://github.com/clj-kondo/clj-kondo/blob/master/doc/types.md ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I think there are two use cases here:
- when used in function variable arguments,
{:op :rest ...}
should be used. - when used in any other place,
:seqable
should be used
e.g. the accept
should know which of the two use cases it is and return accordingly.
src/malli/clj_kondo.cljc
Outdated
(defmethod accept :? [_ _ [child] _] {:op :rest, :spec child}) | ||
(defmethod accept :+ [_ _ _ _] :seqable) | ||
(defmethod accept :* [_ _ _ _] :seqable) | ||
(defmethod accept :? [_ _ _ _] :seqable) | ||
(defmethod accept :repeat [_ _ [child] _] {:op :rest, :spec child}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:repeat
is also one of the sequence schemas that can present more than 1 values.
@@ -63,11 +75,27 @@ | |||
{'kikka | |||
{:arities {1 {:args [:int], | |||
:ret :int}, | |||
:varargs {:args [:int :int {:op :rest, :spec :int}], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a real varargs case and should generate :rest
definition instead :seqable
. From clj-kondo:
{:op :rest, :spec :int}. This can be used to match remaining arguments in vararg signatures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see! Thanks.
:ret :int, | ||
:min-arity 2}}} | ||
'siren | ||
{:arities {2 {:args [:ifn :coll], :ret :map}}}}}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good tests 💪.
cee4aeb
to
ed29740
Compare
- use arity to decide whether to use `{:op :rest}` or `:seqable`
ed29740
to
68d1a82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, feel free to merge 💪
src/malli/clj_kondo.cljc
Outdated
{:op :rest :spec child} | ||
:seqable)) | ||
|
||
(defmethod accept :+ [_ _ children options] (-seqable-or-rest nil nil children options)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to pass the extra nil
values here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the required args.
no need to match accept argument signature use only children and opts.
Update clj-kondo type generation.
{:op :rest}
should be used only for varargs.Setup for validating the changes with clj-kondo: https://github.com/tvaisanen/clj-kondo-malli-error-2022-12-20
closes #820