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

Re: Parameter flags and subscripts and references



On Thu, Nov 13, 2025 at 6:22 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>>
>> print $parameters[nr]
>> nameref-nameref
>>
>> This happens because getpmparameter() presumes that gethashnode2() and
>> getparamnode() will return different results, but resolve_nameref()
>> called from getparamnode() recognizes that a subscripted referent must
>> be the stopping point, and so returns its input.
>
> There are many issues with references to subscripted variables. I worked on that a few months ago. I'll have to resume that work.

Most of these are probably very rarely used cases, so I wouldn't call
this urgent.

Related:

% array=(a b c)
% typeset -n r1=array
% print ${r1[2]}
b
% typeset -n r2='r1[2]'
% print $r2
r

$r2 is implicitly doing ${(!)r1[2]} because of the "stop at
subscripts" behavior.  This could at least be documented (note to
self).

>> The question is, what should the result be?
>
> Given that "$parameters[path[2]]" expands to the empty string, I would expect "$parameters[nr]" to expand to just "nameref". If we ever change "parameters" to return some non-empty value "FOO" for the former then the latter should return "nameref-FOO".

This originated from Daniel's question:
> Should ${(t!)foo} expand to "nameref-scalar" whenever ${parameters[foo]} does?

Maybe the answer is that ${parameters[foo]} should *never* expand to
"nameref-scalar" and should just stop at "nameref" like (t!) does,
regardless of what "foo" represents.




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