Closed rktjmp closed 3 years ago
I think I have a fix for this which should let the compiler options propagate as necessary in this context; can you try the latest?
Yep, using the following options gives no warning, which I think is on spec:
opts = {
env = "_COMPILER",
compilerEnv = _G
}
return function()
return fennel.eval(code, opts), "macro.fnl"
end
λ lua demo.lua
using custom macro searcher loader
my-var (value: 'icecream') compiled at 1628656907
@technomancy The patch part about (set env._G env)
and (local already-warned? {:_G true})
still seems like a smell to me, (local already-warned? {:_G true})
is basically a no-op since it will never be checked against from what I can tell.
Well, the warning system is going away soon anyway, so I'm not too concerned about that.
See demo repo here: https://github.com/rktjmp/fennel-macro-g
I want to use
os
(or likely_G.os
) in a macro, but the existing solutions (as far as I can tell) seem to:allowedGlobals
to include everything likegensym
,tostring
as well as_G
to really function.I can't tell if maybe I am just misunderstanding the docs, misapplying them or if there is a bug.
This line, makes be think that
_G
is supposed to be a "no warning escape hatch", (https://fennel-lang.org/tutorial#strict-global-checking sort of implies that might be the case too).https://github.com/bakpakin/Fennel/blob/4358d6628e6b804f39db37045b34d0cd3803e025/src/fennel/specials.fnl#L954-L956
But keys prefixed with
_G
(i.e_G.os.date
) always come in asos
because of this line:https://github.com/bakpakin/Fennel/blob/4358d6628e6b804f39db37045b34d0cd3803e025/src/fennel/specials.fnl#L1063
Since
_G
exists as a key onenv
, the metatable__index
is never hit (it's only called for missing keys), and so the requested key ends up beingos
, not_G
.The following patch does disable the warning for
_G
, but it also adds_G
to the list of always allowed global which is maybe undesired.Basically I am wondering: