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

Re: [BUG] zsh/param/private scoping error



On Wed, Sep 1, 2021 at 5:10 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>
> Marlon Richert wrote on Wed, Sep 01, 2021 at 14:49:58 +0300:
> > This is not how one would expect private variables to behave. Inside
> > the inner function, the private variable should be completely out of
> > scope and the `tst=` statement should result in the creation of a
> > global variable.
>
> Makes sense to me.  A regression test (one with the 'F' flag) would be
> welcome, if you've got spare tuits.

I was about to create one in V10private.ztst, when I noticed it
appears to exist already on lines 230 - 250. :)

 typeset -A hash_test=(top level)
 () {
  local -Pa array_test=(in function)
  local -PA hash_test=($array_test)
  () {
   print X ${(kv)hash_test}
   hash_test=(even deeper)
   {
     array_test+=(${(kv)hash_test})
   } always {
     print ${array_test-array_test not set} ${(t)array_test}
   }
  }
  print Y ${(kv)hash_test} Z $array_test
 }
 print ${(kv)hash_test} ${(t)array_test}
1:privates are not visible in anonymous functions, part 3
>X top level
>array_test not set
?(anon):4: array_test: attempt to assign private in nested scope
F:future revision will create a global with this assignment




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