This sounds promising, but the trivial implementation described here would actually break some codes. One example is with eval
. If you do @eval a=2
then because eval
is dynamic this takes place in the global (module) scope. So a
gets added to the module, not the function. You’d need to global a
to get the global a
if you also had a local a
, so this is different because in the global scope this would have changed the value of a
instead of making a new one in a different scope.
However, a fancier version of what you’re describing could work if it works around all of these issues automatically by parsing? I’m not sure if that’s possible, but it would be interesting to look into. I’m sure there’s a counter example where it would have a difference that cannot be determined by parsing, like evaling a mutating function will mutate the global which will then not be in a local of the same name or something like that.