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

Singleton arrays treated as scalars



I wrote:
} On Apr 15,  2:08pm, Sven Wischnowsky wrote:
} } Subject: Re: BUG: zsh-3.1.5-pws-14: parameter expansion not working proper
} }
} } Now, we could make the multsub() save (and at the end restore) the
} } value of, say `static int mult_isarr'. It then sets it to zero and
} } calls paramsubst() (via prefork(), as usual). At the end of
} } paramsubst() we set `mult_isarr = isarr'.
} 
} I actually tried this last night -- although I had paramsubst() set the
} static to 0 on the way in; multsub() just saved and restored it -- and
} it worked for some cases but not others, so I decided I was missing a
} subtlety somewhere and threw it out.

I tried this again and got much better results for two-or-more element
arrays, but singleton arrays were still getting subscripted as scalars.
Investigation led me to this fragment of paramsubst():

        if (isarr > 0 && !plan9 && (!aval || !aval[0])) {
            val = dupstring("");
            isarr = 0;
        } else if (isarr && aval && aval[0] && !aval[1]) {
            val = aval[0];
            isarr = 0;
        }

Well, look at that.  If we have a singleton array, make it into a scalar.
This doesn't have anything to do with multsub() at all!

Does anybody remember why this code is here?  What part of the world is
going to come crashing down if that "else if" clause gets deleted?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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