-
Notifications
You must be signed in to change notification settings - Fork 126
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
"use of global <x> is aliased by a local" prevents some compat patterns #299
Comments
I think the original intent here was to highlight places where it looked like there wouldn't be shadowing, but due to mangling there was. Am I remembering correctly or was that a different error? At the very least we should update the fennelfriend message to recommend using |
Ahh, so after digging into the history for a refresher, I believe we left that in there because of the behavior mentioned in this comment in #218. The issue itself was about accidental overwrites due to mangling, but this particular compiler error was put in as a workaround to the edge case mentioned in that comment: (let [print #(print $)] (print 10)) The problem is that because of how Now that we have |
I've fixed the fennelfriend entry here to recommend using |
That seems reasonable. It's possible it'll turn out to be less invasive a change than we think once we start digging into it, but failing that, i'm ok with kicking it to 0.5.0. We can always pull it forward if someone gets motivated to tackle it sooner and the fix turns out to be cleaner than we think. The only issue with |
When intentionally shadowing a global with a local, if the expression refers in any way to the global itself you get a compiler error. For example, this common usecase for writing code that's compatible with Lua 5.1-5.3,
Repro
This assertion was added in 59de14c to get around some possible local/global scope collision issues in the event that the mangled form of a local conflicts with that of a global. While we did know about this when the assertion was added, we decided it was worth adding to avoid bugs on the basis that global-shadowing generally isn't a great idea. However, since there are legitimate usecases like the above, it'd be a good idea to address this in the long run.
One can get around this via
(local unpack (or _G.unpack table.unpack))
, but this is slightly less robust; it wouldn't work, for example, in a custom environment withunpack
on it set via_ENV
orsetfenv
unless it was explicitly put on a new_G
. That's an edge case, but one I think would be worth eventually fixing.When to fix?
This is tied into everything going on in
destructure
, which we've long wanted to pull apart so it isn't coupled so tightly with emitting Lua. We may need to wait until we've brokendestructure
up before we can remove this assertion.The text was updated successfully, but these errors were encountered: