Skip to content

Wrong expansion of inlined forms inside other inlined forms #33

Open
@camsaul

Description

@camsaul

I ran into this issue:

(riddley.walk/macroexpand-all `(= (count [1 2]) (count [3 4])))
;; -> 
(.
 clojure.lang.Util
 clojure.core/equiv
 (. clojure.lang.RT (clojure.core/count [1 2]))
 (clojure.core/count [3 4]))

Note the the = form and the first count form are expanded correctly, but the second count form is not expanded.

Macroexpanding the form generated by the inlined call to = seems to work:

(riddley.walk/macroexpand-all ((-> #'= meta :inline) '(count [1 2]) '(count [3 4])))

(.
 clojure.lang.Util
 clojure.core/equiv
 (. clojure.lang.RT (clojure.core/count [1 2]))
 (. clojure.lang.RT (clojure.core/count [3 4])))

It also seems to work correctly if I replace the calls to count with calls to macros that simply expand to calls to count:

(defmacro my-count [& args]
  `(count ~@args))

(rw/macroexpand-all `(= (my-count [1 2]) (my-count [3 4])))
;; ->
(.
 clojure.lang.Util
 clojure.core/equiv
 (. clojure.lang.RT (clojure.core/count [1 2]))
 (. clojure.lang.RT (clojure.core/count [3 4])))

This doesn't seem to affect every inlined function:

(riddley.walk/macroexpand-all '(+ (count [1]) (count [2])))
;; -> 
(.
 clojure.lang.Numbers
 (add (. clojure.lang.RT (clojure.core/count [1])) (. clojure.lang.RT (clojure.core/count [2]))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions