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

Re: Parameter flags and subscripts and references



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.  This is handled
specially in fetchvalue() after the comment
    /* only happens for namerefs pointing to array elements */
so it needs to be handled in getpmparameter() as well.  The question
is, what should the result be?

There are many issues with references to subscripted variables. I worked on that a few months ago. I'll have to resume that work. It's probably not possible to fix all issues without major refectorings but it looked like smaller changes could still deliver some progress. One takeaway that I remember is that for any progress the part highlighted above had to go away. As a side effect, this would most certainly change the output of the example above.

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".

Philippe



On Thu, Nov 13, 2025 at 6:05 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
There are some oddities with precedence rules.

${(t)path[2]} == 'r' # because ${(t)path} == 'array'

This appears to violate 14.3.3 Rules #3 which says the subscript
should be applied first, but flags are funny things that take effect
at all sorts of the steps, so really this is an omission from the
Rules.  (There also has not been a Rules update for the (!) flag, I
guess that's my failing.)  Are there other flags not mentioned that
should be?

But this flows through to named references:

typeset -n nr='path[2]'
print -r ${(t)nr}
r

This also has another weird effect:

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.  This is handled
specially in fetchvalue() after the comment
    /* only happens for namerefs pointing to array elements */
so it needs to be handled in getpmparameter() as well.  The question
is, what should the result be?

Philippe's "simplify" patch in workers/54063 has no effect on this.



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