Skip to content
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

Merged
merged 3 commits into from
Sep 23, 2023

Conversation

tvaisanen
Copy link
Contributor

@tvaisanen tvaisanen commented Sep 10, 2023

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

Setup for validating the changes with clj-kondo: https://github.com/tvaisanen/clj-kondo-malli-error-2022-12-20

closes #820

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
```
Copy link
Member

@ikitommi ikitommi left a 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:

  1. when used in function variable arguments, {:op :rest ...} should be used.
  2. 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.

(defmethod accept :? [_ _ [child] _] {:op :rest, :spec child})
(defmethod accept :+ [_ _ _ _] :seqable)
(defmethod accept :* [_ _ _ _] :seqable)
(defmethod accept :? [_ _ _ _] :seqable)
(defmethod accept :repeat [_ _ [child] _] {:op :rest, :spec child})
Copy link
Member

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}],
Copy link
Member

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. 

Copy link
Contributor Author

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}}}}}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good tests 💪.

- use arity to decide whether to use `{:op :rest}` or `:seqable`
Copy link
Member

@ikitommi ikitommi left a 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 💪

{:op :rest :spec child}
:seqable))

(defmethod accept :+ [_ _ children options] (-seqable-or-rest nil nil children options))
Copy link
Member

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?

Copy link
Contributor Author

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.
@tvaisanen tvaisanen merged commit 30a2176 into metosin:master Sep 23, 2023
9 checks passed
@tvaisanen tvaisanen deleted the fix/820/clj-kondo-type-export branch September 23, 2023 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Malli generates invalid clj-kondo type spec for [:map [:keys [:+ :keyword]]]
2 participants