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

Support Dart named parameters #2226

Open
valerauko opened this issue Dec 4, 2023 · 6 comments
Open

Support Dart named parameters #2226

valerauko opened this issue Dec 4, 2023 · 6 comments

Comments

@valerauko
Copy link

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Is your feature request related to a problem? Please describe.

ClojureDart supports Dart named parameters. The following is valid:

(defn foo-printer
  [.foo]
  (println foo))
(foo-printer .foo "hello world")

Also apparently at the callsites you can use keywords instead of dotted symbols, but I don't know if this is recommended.
https://github.com/Tensegritics/ClojureDart/blob/fed8bed6e578cb554b3e83f13813b20d58a422f8/doc/differences.md?plain=1#L177-L185

Describe the solution you'd like

Teach clj-kondo to recognize . named parameters in cljd files

Describe alternatives you've considered

Currently we ignore the unresolved symbol warnings in the function body, and the invalid arity warnings at the call sites.

Additional context

I'd love to help implementing this, but I have no idea where to start

@borkdude
Copy link
Member

borkdude commented Dec 4, 2023

Can you create a Dart example to which this compiles? I'd like to learn more about this.

@valerauko
Copy link
Author

Nice tutorial about dart named parameters: https://www.darttutorial.org/dart-tutorial/dart-named-parameters

A usecase in cljd is for example a function that can take a .child like flutter widgets: https://clojurians.slack.com/archives/C03A6GE8D32/p1681981648987529?thread_ts=1681981215.249239&cid=C03A6GE8D32

@borkdude
Copy link
Member

borkdude commented Dec 4, 2023

I guess the easiest solution would be to just ignore all .foo stuff for clojuredart, then right?

@valerauko
Copy link
Author

I'm not sure. Named arguments are not ordered which could result in weird warnings with expected types

I was wondering if something might be possible with 1.11 keyword arguments, but I don't know if those could be made required (which named arguments are)

@borkdude
Copy link
Member

borkdude commented Dec 4, 2023

Maybe for CLJD we have to then transform it internally into :foo 1 :bar 2 and then assume that (defn f [.foo]) will be interpreted as (defn f [& {:keys [foo]}]) or so?

@valerauko
Copy link
Author

With that approach, I'd want to add an extra check because named arguments are required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants