dido/arcueid — Issue #29: Nested environments are wrongly garbage collected
Author: dido
Created: 2012-01-21 03:56:49+00:00
State: open

A bug in garbage collection has been found:

```arc
(let expander
(fn (f var name body)
`(let ,var (,f ,name)
(after (do ,@body) (close ,var))))

(mac w/infile (var name . body)
(expander 'infile var name body))

(mac w/outfile (var name . body)
(expander 'outfile var name body))

(mac w/instring (var str . body)
(expander 'instring var str body))

(mac w/socket (var port . body)
(expander 'open-socket var port body))
)
```
In this portion of arc.arc, the compiler creates an environment with the definition of expander, and uses it to define four macros. This environment should be part of the closures that form the definitions of the macros, so expander is bound in them. However, it would seem that the garbage collector doesn't see the parent environment, and garbage collects it.

Here's a minimal example that should work for illustrating the problem

```arc
(fn (foo)
(assign test (fn (x) (foo x)))) (fn (x) x)
```
Make a unit test involving this code.