Mercerenies / gdlisp

Lisp on the Godot platform
GNU General Public License v3.0
148 stars 1 forks source link

Nested closures don't handle outer class references correctly #138

Closed Mercerenies closed 1 year ago

Mercerenies commented 1 year ago
(defn example () 3)

(defn foo ()
  (new (Reference)
    (defn bar (y) (lambda (x) (example)))))

The lambda inside the lambda class does not correctly inherit the outer class reference needed to access example. That's because, as far as GDLisp is concerned, example is a global function requiring no closure. But on the GDScript side, we synthetically generated an outer class ref inside new to get the right behavior, so that name does need to be closed around in some form (or simply recreated) to be able to access example.