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

cljr-expand-let on a let inside of a let value is confused #488

Open
dgtized opened this issue Apr 30, 2021 · 0 comments
Open

cljr-expand-let on a let inside of a let value is confused #488

dgtized opened this issue Apr 30, 2021 · 0 comments
Labels

Comments

@dgtized
Copy link
Contributor

dgtized commented Apr 30, 2021

When using cljr-expand-let on the let inside of the let value it gets quite confused.

(let [a 1
      b (let [c 2]
          (+ a c))]
  b)

Expected behavior

Any of the following seem reasonable;

(let [a 1
      c 2
      b (+ a c)]
  b)

OR

(let [c 2]
  (let [a 1 
        b (+ a c)]
    b)

OR

Throw an error that it can't manipulate this form.

Actual behavior

;; cljr-expand-let at ^(let [c 2]) =>
(let (let [c 2]
       [a 1
        b (+ a c)])
  b)

Which is not valid clojure. I suspect this may be a tricky problem to resolve correctly as the inner let may encodes dependencies on other vars in the outer let, however, I think if the value is inserted as a key in the parent let immediately before this key it should work? I'm also not sure what should happen if the inner let has more then one key and one depends on the other. IE

(let [a 1
      b (let [c 2
                d (+ a c)]
            d)]
  b)

I guess maybe the operation should just fold all the keys in the inner let to the outer in order? Like so maybe?

(let [a 1
       c 2
       d (+ a c)
       b d]
   b)

Thanks for creating this tool, it's very useful! Also appreciate this particular case is kind of a tricky edge case, but thought it would be useful to report!

Steps to reproduce the problem

Use cljr-expand-let on the inner let.

Environment & Version information

clj-refactor.el version information

clj-refactor 2.5.1 (package: 20210413.733), refactor-nrepl 2.5.1

CIDER version information

;; CIDER 1.1.0 (package: 20210422.802) (Plovdiv), nREPL 0.8.3
;; Clojure 1.10.2, Java 1.8.0_292

Leiningen or Boot version

clojure CLI Version: 1.10.2.774

Emacs version

GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2021-04-30

Operating system

Ubuntu 2020.04

@expez expez added the bug label May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants