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

PATCH: small bug with "typeset -g"



I've been using WARN_CREATE_GLOBAL to look for missing "local" statements
and consequently adding "typeset -g"s in my functions.

I think this is a bug, or should be treated as one:

%  unsetopt typesetsilent
%  silent1(){ typeset -g silence; }
%  silent2(){ local silence; silent1; }
%  silent2
silence=''

The intention is surely simply to ensure that "silence" is defined as a
variable in the enclosing context, so this should be like calls to
typeset that turn flags on or off (even though in practice it doesn't),
which are silent regardless of the setting of TYPESET_SILENT.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.216
diff -u -r1.216 builtin.c
--- Src/builtin.c	31 Oct 2008 23:43:37 -0000	1.216
+++ Src/builtin.c	5 Nov 2008 12:50:07 -0000
@@ -1951,7 +1951,8 @@
 	if (!on && !roff && !value) {
 	    if (OPT_ISSET(ops,'p'))
 		paramtab->printnode(&pm->node, PRINT_TYPESET);
-	    else if (unset(TYPESETSILENT) || OPT_ISSET(ops,'m'))
+	    else if (!OPT_ISSET(ops,'g') &&
+		     (unset(TYPESETSILENT) || OPT_ISSET(ops,'m')))
 		paramtab->printnode(&pm->node, PRINT_INCLUDEVALUE);
 	    return pm;
 	}
Index: Test/B02typeset.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/B02typeset.ztst,v
retrieving revision 1.20
diff -u -r1.20 B02typeset.ztst
--- Test/B02typeset.ztst	15 Sep 2008 08:57:28 -0000	1.20
+++ Test/B02typeset.ztst	5 Nov 2008 12:50:07 -0000
@@ -453,3 +453,9 @@
 >typeset -a array
 >array=(foo bar)
 ?fn:typeset: no such variable: nonexistent
+
+ unsetopt typesetsilent
+ silent1(){ typeset -g silence; }
+ silent2(){ local silence; silent1; }
+ silent2
+0:typeset -g should be silent even without TYPESET_SILENT


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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