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

Re: typeset tied array initialization silently dropped for already tied params



On Sun, 9 Aug 2015 21:47:17 +0200
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> If you already tied SCALAR and array, then doing
> typeset -T SCALAR array=(a b c)
> silently has no effect, other than changing the separator to : or
> whatever you specified there.

The answer seems to be not to do that.

diff --git a/Src/builtin.c b/Src/builtin.c
index c63be7e..4a97a31 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2685,6 +2685,8 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 		    tdp->joinchar = joinchar;
 		    if (asg0.value.scalar)
 			setsparam(asg0.name, ztrdup(asg0.value.scalar));
+		    else if (asg->value.array)
+			setaparam(asg->name, zlinklist2array(asg->value.array));
 		    return 0;
 		} else {
 		    zwarnnam(name, "can't tie already tied scalar: %s",
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index a059442..2b8e544 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -467,9 +467,12 @@
  print $tied_array
  typeset -T TIED_SCALAR=goo:car tied_array
  print $tied_array
+ typeset -T TIED_SCALAR tied_array=(poo par)
+ print $TIED_SCALAR
 0:retying arrays to same array works
 >foo bar
 >goo car
+>poo:par
 
  (
    setopt POSIXBUILTINS



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