zsh-workers
 help / color / mirror / code / Atom feed
* Crash bug in typeset -T
@ 2011-02-28  6:37 Bart Schaefer
  2011-02-28  9:49 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2011-02-28  6:37 UTC (permalink / raw)
  To: zsh-workers

torch% typeset -T FOO foo
torch% typeset -p FOO foo
typeset FOO=''
typeset -a foo
foo=()

So far, so good.  Now:

torch% typeset -T FOO bar
torch% typeset -p FOO foo bar
typeset FOO=''
typeset -a foo
foo=('')
typeset -a bar
bar=()

Curious, look what happened to $foo.  Now:

torch% unset FOO
torch% typeset -p FOO foo bar
typeset: no such variable: FOO
typeset: no such variable: bar
typeset -a foo
foo=()
torch% foo=(x y z)
zsh: segmentation fault (core dumped)  Src/zsh -f

Similar things happen if you unset the array instead of the scalar:

torch% typeset -T FOO foo
torch% typeset -T FOO bar
torch% unset foo
torch% typeset -p FOO foo bar
typeset: no such variable: FOO
typeset: no such variable: foo
typeset -a bar
bar=()
torch% bar=(x y z)
zsh: segmentation fault (core dumped)  Src/zsh -f

This also happens if you unset bar and then assign to foo.  (What I was
looking for when I found this, was a way to untie FOO from foo without
unsetting both of them.)  Related oddness:

torch% typeset -T FOO foo
torch% typeset -T FOO=x:y:z bar
torch% typeset -p FOO foo bar
typeset FOO=x:y:z
typeset -a foo
foo=(x y z)
typeset -a bar
bar=()

Note that foo got the value assigned to FOO, bar did not.  If FOO and foo
were not already tied, bar would have had the value.  Yet:

torch% unset bar
torch% typeset -p FOO foo bar
typeset: no such variable: FOO
typeset: no such variable: bar
typeset -a foo
foo=()

Obviously "typeset -T" needs to check if it's being applied to a parameter
that's already tied ... but what should it do in that case?  Error?  Unset
and then re-tie?  There is precedent for the latter - a change of type of
either variable in the tied pair, unsets the other:

torch% typeset -T FOO=1 foo
torch% typeset -i FOO
torch% typeset -p FOO foo
typeset: no such variable: foo
typeset -i FOO=1

Of course what I was hoping was that "typeset +T" would disentangle the
variables yet leave them independently set, but:

torch% typeset +T FOO
typeset: use unset to remove tied variables


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-03-01  4:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-28  6:37 Crash bug in typeset -T Bart Schaefer
2011-02-28  9:49 ` Peter Stephenson
2011-03-01  4:00   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).