Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Undetected self references
- X-seq: zsh-workers 53670
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Undetected self references
- Date: Thu, 22 May 2025 20:37:53 -0700
- Archived-at: <https://zsh.org/workers/53670>
- In-reply-to: <CAGdYchuhuURJV=zoaXfi7-p=rfKh828M4gAtDOHX4byMcdVBoA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchuhuURJV=zoaXfi7-p=rfKh828M4gAtDOHX4byMcdVBoA@mail.gmail.com>
On Wed, May 21, 2025 at 6:24 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>>
> I think you overlook something or there is something fundamental that I don't understand.
You're right, I did overlook something. There is a circular
reference, but it's not undetected, it's just unreported.
> f1 () {
> typeset -n ref1=ref2
> typeset -n ref2
> f2 () {
> f3 () {
> typeset ref1=inner;
> ref2=ref1
> echo "$0: ref1=$ref1 ref2=$ref2"
> }
> f3
> echo "$0: ref1=$ref1 ref2=$ref2"
> ref1=foo
> }
> f2
> }
> f1
Look what happens here:
% ref2=GLOBAL
% f1
f3: ref1=inner ref2=inner
f2: ref1=GLOBAL ref2=GLOBAL
This is what threw me off. Because of parameter hiding, neither "echo
$ref" nor "typeset -p ref" can tell you which scope ref2 is in, so my
conclusion was that the chain ended in a non-reference.
What actually happens is that my loop-detection algorithm was
correctly finding the cycle and stopping the recursion, but the entry
point via parameter substitution doesn't check for the error
condition. The entry point via assignment does check it.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author