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

Re: Typeset with array

On Fri, 19 Jun 2015 09:09:04 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 1. It's now possible to assign both arrays and scalars in one statement.
>  - what happens for  typeset -a x="string" y=(word list)  ??

Oliver noted this, too (most of his examples should in principle do
something sensible eventually but I haven't got round to that level of
detail yet).  I think it doesn't matter that much if either this gets
silently turned into x=("string"), or if there's an error on the x
assignment, as long as we pick one and document it.

> 2. We don't have a distinct syntax for associative array assignment, so
> this still works only for ordinary arrays.
>  - ksh of course uses  h=([key] value)  to assign an associative array.

Well, we don't have that syntax, but this should work:

  typeset -A hash=(bob robert bill william)

but doesn't because of a bug fixed below.  If you're playing along at
home --- this is exclusive to the typeset-array branch.


diff --git a/Src/builtin.c b/Src/builtin.c
index b34669f..6cccf53 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -1998,7 +1998,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
     /* attempting a type conversion, or making a tied colonarray? */
     tc = 0;
-    if (ASG_ARRAYP(asg))
+    if (ASG_ARRAYP(asg) && PM_TYPE(on) == PM_SCALAR)
 	on |= PM_ARRAY;
     if (usepm && ASG_ARRAYP(asg) && newspecial == NS_NONE &&
 	PM_TYPE(pm->node.flags) != PM_ARRAY &&

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