~technomancy/fennel

73235cfbad79a77c47fa38a9488c7a32dc4aa8f8 — Phil Hagelberg 6 days ago a80fa71
Fix a bug in method calls with non-native names.
3 files changed, 5 insertions(+), 4 deletions(-)

M changelog.md
M src/fennel/specials.fnl
M test/core.fnl
M changelog.md => changelog.md +1 -1
@@ 2,7 2,7 @@

## 0.6.1 / ???

* ???
* Fix a bug in `:` when used with methods that are not valid Lua names.

## 0.6.0 / 2020-09-03


M src/fennel/specials.fnl => src/fennel/specials.fnl +2 -3
@@ 584,10 584,9 @@ Evaluates body once for each value between start and stop (inclusive).")
  "When we don't have to protect against double-evaluation, it's not so bad."
  (let [method-string (tostring (. (compiler.compile1 (. ast 3) scope parent
                                                      {:nval 1}) 1))]
    (table.insert args (tostring target))
    (utils.expr (string.format "%s[%s](%s)" (tostring target) method-string
    (utils.expr (string.format "%s[%s](%s, %s)" (tostring target) method-string
                               (tostring target)
                               (table.concat args ", ")) "statement")))
                               (table.concat args ", ")) :statement)))

(fn double-eval-protected-method-call [ast scope parent target args]
  "When double-evaluation is a concern, we have to wrap an IIFE."

M test/core.fnl => test/core.fnl +2 -0
@@ 90,6 90,8 @@

               ;; method calls work
               "(: :hello :find :e)" 2
               ;; method calls work on identifiers that aren't valid lua
               "(let [f {:+ #(+ $2 $3 $4)}] (f:+ 1 2 9))" 12
               ;; method calls don't double up side effects
               "(var a 0) (let [f (fn [] (set a (+ a 1)) :hi)] (: (f) :find :h)) a" 1