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

BUG: Initializations of named references with an empty string should trigger an error



function f {
  typeset -n ref
  typeset var=foo
  ref=$1
  echo ref=$ref
  ref=var
  echo ref=$ref
}


$ f var
ref=foo
ref=var

In this call to foo the first assignment to ref (ref=$1) initializes the reference and the second one (ref=var) assigns the string var to the referred variable.

$ f ""
ref=
ref=foo

In this call to foo, the first assignemnt to ref has no effect and the second one becomes an initialization of ref. I find this very surprising. In my opinion, only the first assignment to an uninitialized named reference should ever be an initialization of the named reference.

Here is what ksh does:

$ f ""
ksh: f: line 4: : invalid variable name

I think that this is much better and that Zsh should do the same,

Philippe



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