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

Re: Nasty bug in array-element typeset assignments



Good grief, this is the most discussion on a single topic in weeks.  I
shouldn't have gone to bed last night, I guess.

On Jul 26, 10:44am, Peter Stephenson wrote:
}
} When you add to this the restore sequence, which is handled at the
} end of function scope with no detailed knowledge of what typeset has been
} up to, you've got something very difficult to maintain

It's not supposed to create a local *element*, it's just supposed to
assign to an element of a local array.

On Jul 26,  1:57pm, Borsenkow Andrej wrote:
}
} BTW it is allowed in 4.0.2, I do not have earlier versions here readily
} available. May be, it was always possible?

See 14060, as Andrej already mentioned -- it was always possible, but
badly broken.  It seemed useful to me, so I tried to fix it rather
than prevent it.

I discovered the bug when writing this:

	function example() {
	  local 'new_array[$#new_array+1]'=$^old_array
	  # ...
	}

The above works beautifully, and is equivalent to what you'd get if the
syntax `local new_array=( $old_array )' worked.

In fact, the following also works, and does not cause a core dump:

	function example() {
	  local path 'path[$#path+1]'=$^path
	  # ...
	}

Because in the above statement, `path' is made local before the elements
are assigned.  Et voila.

On Jul 26, 12:07pm, Oliver Kiddle wrote:
}
} I wrote:
} > However, I wouldnt have thought it'd be too
} > hard to get it to print an error message for the above case.
} 
} This might be useful for 4.0.2 so the following is a patch to do that
} much.

There was never any patch following ... but that's just as well, because
I don't want to print an error in this case, unless possibly the array
is non-local.

On Jul 26, 12:38pm, Oliver Kiddle wrote:
}
} > Probably, intent was to create new local array.
} 
} Urgh. Is that really that useful?

It's really useful (see above), but it's not really necessary (also see
above).

} Also, if this is fixed to make the whole array local but the fix is
} complicated then this small change might be a good option for the 4.0
} branch.

I think there's a simple fix we can do without disallowing it entirely.

On Jul 26, 12:45pm, Peter Stephenson wrote:
}
} Something like that would definitely be my preference.

I have something working that's actually a very small change, and still
permits my second example above to work (while rejecting the first one).
Let me play with a few more cases so I can put the right regression tests
in D06 -- it'll probably be several hours before I get to concentrate on
it.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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