-
Notifications
You must be signed in to change notification settings - Fork 89
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
Variables in case expressions shadow across branches (when source names shadow) #365
Comments
Yeah, I guess renaming would be more performant. Probably that would be nice for reading the code in general, that shadowed variables are differentiated. |
Oh, another idea, just use closures, but then make a pass that generally transforms unneeded immediately-applied closures, as an optimization. Such as the |
Yeah, Closure optimizes redundant closures away:
|
Since IF blocks usually contain return statements, but sometimes do not. How can we know if we should wrap the block with {return (function(){BLOCK;})();} or with {(function(){ BLOCK })();}? |
We shouldn't do this translation for all if statements, just when pattern matching. Here we know that a branch will always return if the pattern (and guard, if it's present) matches. |
Yeah, ifs don't introduce bindings, so they're not affected. |
Oh, misinterpreted. Yeah. |
Thanks to @bsummer4 for reporting this.
Relevant generated code:
Because JS
if
does not introduce a new scope,a
in theM
branch refers to thea
in theMI
branch. We need to either generate a unique name for all bindings like this (but we don't have name tracking so it would become$gen1
), or put all cases in a closure. Best would be if we could check if the identifier is in scope and only then rename it.Workaround: Compile with
--Wall
and make sure variables aren't shadowed.The text was updated successfully, but these errors were encountered: