-
-
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
symbol declared in template is considered undeclared if symbol with same name is injected into proc in same template #14620
Comments
Here's a further minimized failing example: x.nim(8, 1) Error: undeclared identifier: 'x' template t =
proc p =
let x {.inject.} = 1
let x = 1
x
t Apparently, any use of a variable declared within the template with the same name as a symbol injected into the proc fails because the compiler erroneously thinks the symbol isn't declared. |
Seems like a duplicate or really similar to #10609 |
Yes, it's the same. The dump in Bluenote10's comment on #10609 makes it
evident that the inject in the proc causes subsequent uses (but not
declarations) of gensymed symbols with the same name to be treated as if
they are injected ... thus the x in my examples is undeclared because it is
plain x, not the gensymed name that was declared with for or let. People
in the forum noted that there's no error if the second x, outside the proc,
is also injected ... which makes sense because then the bug isn't triggered
... the declared symbol and the used symbol match.
…On Wed, Jun 10, 2020, 1:49 AM Danil Yarantsev ***@***.***> wrote:
Duplicate or really similar to #10609
<#10609> maybe?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#14620 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEDT2BBQJVWDDVJXCYJHE3RV5CJ3ANCNFSM4NZX573A>
.
|
Here's an example that illustrates what's happening: template t(body: untyped) =
proc p =
let x {.inject.} = 0
let x = 1
body
echo x
t:
let x = 2 This prints 2 rather than 1 because |
nim 1.2 on Windows 10
Error message:
x.nim(9, 1) template/generic instantiation of
t
from herex.nim(7, 9) Error: undeclared identifier: 'x' [line is
bod(x)
]from this code:
x
is of course declared, contrary to the error message. The injectedx
is local to procbod
, and even if one of thesex
"overrides" the other (which makes no sense), the error message makes no sense -- there appears to be some sort of mishandling of the symbol table within the template. There's no error if the argument tobod
doesn't referencex
, or if thelet
is moved outside of the template, e.g.,This also works fine, as the two
x
s are not in the same template:The text was updated successfully, but these errors were encountered: