-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding .gensym. to a template does not make it local #2465
Comments
From the manual:
so it does exactly what you tell it to.
Results in
as expected. |
I was wondering about this bug. I didn't think it was one at first, but I saw that Araq called it a bug in this forum comment. Looking at it again, shouldn't the
|
In case you didn't realize, the reason you're getting:
Is because in your example you didn't have {.inject.} on the x:
My full example is repeated here with the compile & run output:
As @goob said I would expect this to generate a compile error saying "declX" is undeclared. Instead it works. |
The template t() =
template foo() {.gensym.} =
echo 42
t()
foo() |
was about to file a new bug (which I ran into while working on #11722) but I found this, looks like the same or similar: import std/macros
macro mgen(): untyped =
let name1 = genSym(nskTemplate, "mypriv1")
let name2 = genSym(nskProc, "mypriv2")
let name3 = genSym(nskLet, "mypriv3")
result = newStmtList()
result.add quote do:
template `name1`() = echo "in template"
proc `name2`() = echo "in proc"
proc bobah() = echo "in bobah"
let `name3` = 123
echo repr(result)
return result
mgen()
bobah() # ok, works
mypriv1() # BUG: this shouldn't compile, it's genSym'd
when false:
mypriv2() # inconsistent with mypriv1: this one doesn't compile
echo mypriv3 # ditto
mypriv1421054() # the gensym'd name doesn't compile either
mypriv2421053() # ditto for mypriv2 notethis could affect all code with workaroundhere's the workaround I found that seems to work: use a name with an underscore, making it impossible to clash: let name = genSym(nskTemplate, "_fun") |
the bug in top post is now fixed (as of 6aa971d 1.3.5 at least) but the bug in #2465 (comment) is still here maybe a simple hacky fix would be to force gensym idents to start with |
* new `macros.genAst`: fixes all issues with `quote do` * add changelog entry * add workaround for #2465 (comment) * add test for #9607 * add kNoExposeLocalInjects option * add test case for nested application of genAst * genAst: automatically call newLit when needed * allow skipping `{}`: genAst: foo * add test that shows this fixes #11986 * add examples showing mixin; add examples showing passing types, macros, templates * move to std/genasts * improve docs
Now: template t() =
template foo() {.gensym.} =
echo 42
t()
foo() Gives:
|
closes nim-lang#12582, closes nim-lang#19552, closes nim-lang#2465, closes nim-lang#4596, closes nim-lang#15246, closes nim-lang#12683, closes nim-lang#7889, closes nim-lang#4547, closes nim-lang#12415, closes nim-lang#2002, closes nim-lang#1771, closes nim-lang#5121 The test for nim-lang#5648 is also moved into its own test from `types/tissues_types` due to not being joinable.
* test case haul for old generic/template/macro issues closes #12582, closes #19552, closes #2465, closes #4596, closes #15246, closes #12683, closes #7889, closes #4547, closes #12415, closes #2002, closes #1771, closes #5121 The test for #5648 is also moved into its own test from `types/tissues_types` due to not being joinable. * fix template gensym test
* test case haul for old generic/template/macro issues closes #12582, closes #19552, closes #2465, closes #4596, closes #15246, closes #12683, closes #7889, closes #4547, closes #12415, closes #2002, closes #1771, closes #5121 The test for #5648 is also moved into its own test from `types/tissues_types` due to not being joinable. * fix template gensym test (cherry picked from commit c19fd69)
* test case haul for old generic/template/macro issues closes #12582, closes #19552, closes #2465, closes #4596, closes #15246, closes #12683, closes #7889, closes #4547, closes #12415, closes #2002, closes #1771, closes #5121 The test for #5648 is also moved into its own test from `types/tissues_types` due to not being joinable. * fix template gensym test (cherry picked from commit c19fd69)
When compiling:
The text was updated successfully, but these errors were encountered: