Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: LOCAL_VARS option ?



On Fri, 20 Jan 2017, Peter Stephenson wrote:

> Here's a first go at the warning option, with "functions -W" to turn it on
> in the same fashion as "functions -T".  The option is called
> WARN_NESTED_VAR for now.

This is almost exactly what I was thinking ... except I wasn't thinking
of it having a name that could be accessed with setopt.  I was thinking
more of something that could ONLY be activated by "functions -W".

Still, I can see it either way, so thanks for the prototype.

> The main drawback over WARN_CREATE_GLOBAL is that "typeset -g" doesn't
> mark the variable for future assignments; it's still in a global scope
> so still gets a warning next time.  I think that's correct behaviour

It certainly seems reasonable.

Possible logical extensions would be to warn only if the variable is
truly in global scope, or to warn only if the variable is NOT in global
scope (i.e., is local to some caller's scope).  If -W were implemented
in some other way than as a setopt, it could accept arguments (along
the lines of gcc -W...) to indicate different kinds of warnings.



Messages sorted by: Reverse Date, Date, Thread, Author