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

False positive with destructuring depending on previous arg #782

Closed
marcomorain opened this issue Mar 2, 2020 · 4 comments
Closed

False positive with destructuring depending on previous arg #782

marcomorain opened this issue Mar 2, 2020 · 4 comments
Projects

Comments

@marcomorain
Copy link
Contributor

marcomorain commented Mar 2, 2020

version

clj-kondo v2020.02.28

platform

Native on macOS:

Darwin blaster.local 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64

editor

Calva

problem

(fn unresolved-symbol-x
  [x & {:keys [y]
          :or {y (inc x)}}]
  (+ y x))

repro

echo '(fn unresolved-symbol-x [x & {:keys [y] :or {y (inc x)}}] (+ y x))' | clj-kondo --lint -

marc@blaster ~/dev/circleci/circle $ echo '(fn unresolved-symbol-x [x & {:keys [y] :or {y (inc x)}}] (+ y x))' | clj-kondo --lint -
<stdin>:1:53: error: unresolved symbol x
linting took 19ms, errors: 1, warnings: 0

expected behavior

This code is valid as far as I understand, so no warnings.

@borkdude borkdude added this to Needs triage in clj-kondo via automation Mar 2, 2020
@borkdude borkdude changed the title False positive with destructuring False positive with :or destructuring with default depending on previous arg Mar 2, 2020
@borkdude
Copy link
Member

borkdude commented Mar 2, 2020

I'm closing this as this is undefined behavior and people should not rely on this.

Screenshot 2020-03-02 17 16 43

@borkdude borkdude closed this as completed Mar 2, 2020
clj-kondo automation moved this from Needs triage to Done Mar 2, 2020
@borkdude borkdude changed the title False positive with :or destructuring with default depending on previous arg False positive with destructuring depending on previous arg Mar 6, 2020
@borkdude
Copy link
Member

borkdude commented Mar 6, 2020

Dump from another example on Slack:

4:56 PM
oliy Hi, me again. I've found a false positive pair in unused binding field and unresolved symbol field with this:

(defn foo [k {v k}] v)
(foo :a {:a 1}) ;; -> 1

new messages
4:57 PM
(both instances of k are highlighted respectively)
5:00 PM
borkdude @oliy don't do this.
https://github.com/borkdude/clj-kondo/issues/782 (edited) 
5:01 PM
oliy Ah thank you, I searched but it was hard to know how to describe the code :)
5:01 PM
borkdude If you think this is supported by Clojure (and not just accidental behavior) talk to Alex Miller or anyone else from the core team. If they think it should be supported as official Clojure, I would be happy to fix it.
5:01 PM
But as of now it seems they don't support it.
5:01 PM
oliy Yeah I find it hard to read myself so I'm not a fan of it, but it is wonderfully terse
5:01 PM
I'll just rewrite

@borkdude
Copy link
Member

#673 (comment):

puredanger wrote:

this is undefined and you should not do that

@borkdude
Copy link
Member

See #916: this behavior is supported.

There are only some circumstances where this is not supported, e.g. when relying on the order in maps.
But your example was not one of them.

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

No branches or pull requests

2 participants