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

[PATCH] Fix a WARN_CREATE_GLOBAL false positive.



---
This seems to be a false positive:

    % zsh -fc 'setopt warn_create_global; (){ x=y =true }'
    (anon): scalar parameter x created globally in function

Regression test attached.  I'm less sure about the patch, but it seems to
work and is unlikely to break anything other than WARN_CREATE_GLOBAL.

Daniel

 Src/exec.c           |    5 ++++-
 Test/E01options.ztst |    1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git Src/exec.c Src/exec.c
index df915e1..dccdc2b 100644
--- Src/exec.c
+++ Src/exec.c
@@ -3309,7 +3309,10 @@ execcmd(Estate state, int input, int output, int how, int last1)
 	    }
 	    if (type == WC_SIMPLE) {
 		if (varspc) {
-		    addvars(state, varspc, ADDVAR_EXPORT|ADDVAR_RESTRICT);
+		    int addflags = ADDVAR_EXPORT|ADDVAR_RESTRICT;
+		    if (forked)
+			addflags |= ADDVAR_RESTORE;
+		    addvars(state, varspc, addflags);
 		    if (errflag)
 			_exit(1);
 		}
diff --git Test/E01options.ztst Test/E01options.ztst
index e00eb0e..48f3ffc 100644
--- Test/E01options.ztst
+++ Test/E01options.ztst
@@ -1067,6 +1067,7 @@
     fn2() {
       foo3=bar6
     }
+    foo4=bar7 =true
   }
   fn
 0:WARN_CREATE_GLOBAL option
-- 
1.7.10.4



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