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

[PATCH] Perform cumulative typesetting also on parameters with no value



Typesetting multiple times the same parameter with different flags but without changing its type should be cumulative. This currently fails for parameters declared with no value when TYPESET_TO_UNSET is enabled.

% setopt TYPESET_TO_UNSET
% typeset -u var1=foo var2
% typeset -p var1 var2
typeset -u var1=foo
typeset -u var2
% typeset -x var1 var2
% typeset -p var1 var2
export -u var1=foo
export var2

The last line should include -u, like the previous one.

Perform cumulative typesetting also on parameters with no value

Philippe

diff --git a/Src/builtin.c b/Src/builtin.c
index 2e3e5752a..61d2a2730 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2055,7 +2055,8 @@ typeset_single(char *cname, char *pname, Param pm, int func,
      * POSIXBUILTINS horror: we need to retain the 'readonly' or 'export'
      * flags of an unset parameter.
      */
-    usepm = pm && (!(pm->node.flags & PM_UNSET) || OPT_ISSET(ops, 'p') ||
+    usepm = pm && (!(pm->node.flags & PM_UNSET) ||
+		   (pm->node.flags & PM_DECLARED) || OPT_ISSET(ops, 'p') ||
 		   (isset(POSIXBUILTINS) &&
 		    (pm->node.flags & (PM_READONLY|PM_EXPORTED))));
 
@@ -2279,7 +2280,8 @@ typeset_single(char *cname, char *pname, Param pm, int func,
 	/*
 	 * Keep unset if using readonly in POSIX mode unless specified otherwise.
 	 */
-	if ((usepm != 2) && !((on & PM_READONLY) && isset(POSIXBUILTINS)))
+	if ((usepm != 2) && !((on & PM_READONLY) && isset(POSIXBUILTINS)) &&
+	    !(pm->node.flags & PM_DECLARED))
 	    off |= PM_UNSET;
 	pm->node.flags = (pm->node.flags | (on & ~PM_READONLY)) & ~off;
 	if (on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z)) {
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index 32e79ced2..7bc44dbdc 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -174,6 +174,34 @@
 >inner
 >outer
 
+ addflags() {
+   setopt localoptions typeset_to_unset
+   if ((ARGC == 2)); then typeset $1=$2; else typeset $1; fi
+   typeset -p $1
+   typeset -R5 $1
+   typeset -p $1
+   typeset -u $1
+   typeset -p $1
+   typeset -x $1
+   typeset -p $1
+ }
+ addflags var1 foo
+ addflags var2 ""
+ addflags var3
+0:Typesetting is cumulative
+>typeset var1=foo
+>typeset -R5 var1=foo
+>typeset -R5 -u var1=foo
+>local -R5 -ux var1=foo
+>typeset var2=''
+>typeset -R5 var2=''
+>typeset -R5 -u var2=''
+>local -R5 -ux var2=''
+>typeset var3
+>typeset -R5 var3
+>typeset -R5 -u var3
+>local -R5 -ux var3
+
  float f=3.14159
  typeset +m f
  float -E3 f


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