diff --git a/src/riddley/walk.clj b/src/riddley/walk.clj index b561c3e..02cb49e 100644 --- a/src/riddley/walk.clj +++ b/src/riddley/walk.clj @@ -31,8 +31,7 @@ (inline-fn '(+ 1 2)) ; -> #function[clojure.core/nary-inline/fn--5541] (inline-fn '(+ 1 2)) ; -> nil" [form] - (when (and (seq? form) - (not (::transformed (meta form)))) + (when (seq? form) (let [[fn-symbol & args] form] (when (symbol? fn-symbol) ;; a function is inlineable if it has an `:inline` function in its metadata, and, if it has an @@ -50,16 +49,9 @@ ([form special-form?] (let [inline-fn (or (inline-fn form) - (throw (ex-info "Form is not an inlineable function call." {:form form}))) - expanded (with-meta (apply inline-fn (rest form)) (meta form))] + (throw (ex-info "Form is not an inlineable function call." {:form form})))] (macroexpand - ;; unfortunately, static function calls can look a lot like what we just - ;; expanded, so prevent infinite expansion - (if (head= expanded '.) - (with-meta - (concat (butlast expanded) [(merge-meta (last expanded) {::transformed true})]) - (meta expanded)) - expanded) + (with-meta (apply inline-fn (rest form)) (meta form)) special-form?)))) (defn- expand-list-like diff --git a/test/riddley/walk_test.clj b/test/riddley/walk_test.clj index 6c9173c..6fd35f2 100644 --- a/test/riddley/walk_test.clj +++ b/test/riddley/walk_test.clj @@ -50,10 +50,7 @@ `(int 1) true `(n 1) nil `+ nil - `n nil} - ;; any form with `::transformed` in its metadata should always come back as nil - [form expected] [[form expected] - [(with-meta form {:riddley.walk/transformed true}) nil]]] + `n nil}] (testing (binding [*print-meta* true] (pr-str (list 'inline-fn? form))) (if expected (is (fn? (r/inline-fn form))) @@ -70,12 +67,12 @@ (deftest expand-inline-fn-test (is (= '(. clojure.lang.Numbers (and 2 1)) - (r/expand-inline-fn '(bit-and 2 1) nil))) + (r/expand-inline-fn '(bit-and 2 1)))) (testing "Should throw an Exception if the form is not inlineable" (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Form is not an inlineable function call" - (r/expand-inline-fn '(+ 1) nil))))) + (r/expand-inline-fn '(+ 1)))))) (deftest test-walk-exprs ;; the first and third numbers get incremented, but not the second @@ -223,3 +220,12 @@ (deftest meta-data-on-inline-function-macro-expasion (is (= {:foo :bar} (meta (r/macroexpand (with-meta '(+ 1 1) {:foo :bar})))))) + +(deftest expand-nested-inline-fn-calls-test + (testing "Nested inlined function calls should get expanded correctly (#33)" + (is (= '(. + clojure.lang.Util + clojure.core/equiv + (. clojure.lang.RT (clojure.core/count [1 2])) + (. clojure.lang.RT (clojure.core/count [3 4]))) + (r/macroexpand-all `(= (count [1 2]) (count [3 4])))))))