about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-01-23 09:50:57 +0000
committerPeter Stephenson <pws@zsh.org>2017-01-23 09:50:57 +0000
commitc861b17bbf002129f29e22ab625fd3516ba792a2 (patch)
treed1cd26c6a1f298840fd51fae19a4a25f279ecf10 /Src/exec.c
parent8cb130fe7311aa428e93978eeceb5ab141959aa6 (diff)
downloadzsh-c861b17bbf002129f29e22ab625fd3516ba792a2.tar.gz
zsh-c861b17bbf002129f29e22ab625fd3516ba792a2.tar.xz
zsh-c861b17bbf002129f29e22ab625fd3516ba792a2.zip
40391: Add WARN_NESTED_VAR option and functions -W.
These are companions to WARN_CREATED_GLOBAL, warning when a variable
from an enclosing scope is altered.
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 6c8264394..8f4969f52 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2379,9 +2379,7 @@ addvars(Estate state, Wordcode pc, int addflags)
      * to be restored after the command, since then the assignment
      * is implicitly scoped.
      */
-    flags = (!(addflags & ADDVAR_RESTORE) &&
-	     locallevel > forklevel && isset(WARNCREATEGLOBAL)) ?
-	ASSPM_WARN_CREATE : 0;
+    flags = !(addflags & ADDVAR_RESTORE) ? ASSPM_WARN : 0;
     xtr = isset(XTRACE);
     if (xtr) {
 	printprompt4();
@@ -5431,6 +5429,14 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
 	    else
 		opts[XTRACE] = 0;
 	}
+	if (flags & PM_WARNNESTED)
+	    opts[WARNNESTEDVAR] = 1;
+	else if (oflags & PM_WARNNESTED) {
+	    if (shfunc->node.nam == ANONYMOUS_FUNCTION_NAME)
+		flags |= PM_WARNNESTED;
+	    else
+		opts[WARNNESTEDVAR] = 0;
+	}
 	ooflags = oflags;
 	/*
 	 * oflags is static, because we compare it on the next recursive
@@ -5549,6 +5555,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
 	    opts[PRINTEXITVALUE] = saveopts[PRINTEXITVALUE];
 	    opts[LOCALOPTIONS] = saveopts[LOCALOPTIONS];
 	    opts[LOCALLOOPS] = saveopts[LOCALLOOPS];
+	    opts[WARNNESTEDVAR] = saveopts[WARNNESTEDVAR];
 	}
 
 	if (opts[LOCALLOOPS]) {