~technomancy/fennel#249: 
macro hygiene: generated symbols can be referenced

Imagine I have this macro that injects a symbol into its environment.

(macro inject [] `(local foo# 10))
(inject)

;;prints 10, but *should* be `unknown identifier: foo_2_auto` or print `nil`
(print foo_2_auto)

I'm not an expert on macro hygenics, but in my mental model, I would expect foo# to be in scope, but be unnameable and inaccessible. Unexpectedly, if you can predict the generated name, (in this case foo_2_auto) you can gain access to the local.

Status
REPORTED
Submitter
~xerool
Assigned to
No-one
Submitted
a month ago
Updated
a month ago
Labels
bug

~technomancy a month ago

I haven't thought this thru all the way, but I think the only way to prevent this is to make it so that foo# does not expand to foo_2_auto until right before it's emitted as Lua. However, this may cause backwards-incompatibility issues with existing macros.

Register here or Log in to comment, or comment via email.