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

Re: PATCH: array slice



On Fri, 26 Jun 2015 16:07:45 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> This error message looks odd:
> 
> torch% typeset y[2,4]=(x)
> typeset: y[2,4]: can't create local array elements
> 
> I guess that isn't new, but to refer to "local" at top-level prompt is
> funny.  "(on & PM_LOCAL)" is evidently true even though the typeset is
> not within function scope.  Amusingly it works to simply force the
> variable to be global:
> 
> torch% typeset -g y[2,4]=(x)            
> torch% typeset -p y
> typeset -a y
> y=('' x)
> 
> And an array is always created for this, even without the parens:
> 
> torch% typeset -g z[2,4]=y
> torch% typeset -p z       
> typeset -a z
> z=('' y)

OK, so it does work if it *would* create a local if it could but is
*actually* going to create a global in practice.  This probably isn't
all that useful in practice --- in the second case, you haven't even
told it you want an array.

It would take more work to fix this so it does something sensible if the
variable would be local --- we get into a mess later, which is what I
think the error is for.  I don't quite understand why but I've
lost interest / the will to live; there are too many combinations.

pws

--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2325,7 +2325,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	    zerrnam(cname,
 		    "%s: can't create readonly array elements", pname);
 	    return NULL;
-	} else if (on & PM_LOCAL) {
+	} else if ((on & PM_LOCAL) && locallevel) {
 	    *subscript = 0;
 	    pm = (Param) (paramtab == realparamtab ?
 			  gethashnode2(paramtab, pname) :



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