diff options
author | Peter Stephenson <p.w.stephenson@ntlworld.com> | 2015-02-13 21:31:31 +0000 |
---|---|---|
committer | Peter Stephenson <p.w.stephenson@ntlworld.com> | 2015-02-13 21:31:31 +0000 |
commit | daa7d99702b8a3580b71ee74f962719ad1d052c8 (patch) | |
tree | 664926219037f1d809ec3fb6db372b510c21c4b7 /Src | |
parent | 7e6faf7237b1862fce3ebc34f09ee9ac07940638 (diff) | |
download | zsh-daa7d99702b8a3580b71ee74f962719ad1d052c8.tar.gz zsh-daa7d99702b8a3580b71ee74f962719ad1d052c8.tar.xz zsh-daa7d99702b8a3580b71ee74f962719ad1d052c8.zip |
34546: further $_ with anon function fix.
Also add tests.
Diffstat (limited to 'Src')
-rw-r--r-- | Src/exec.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Src/exec.c b/Src/exec.c index 302e2b510..de6b9c574 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2784,9 +2784,14 @@ execcmd(Estate state, int input, int output, int how, int last1) else text = NULL; - /* Set up special parameter $_ */ - - setunderscore((args && nonempty(args)) ? ((char *) getdata(lastnode(args))) : ""); + /* + * Set up special parameter $_ + * For execfuncdef we may need to take account of an + * anonymous function with arguments. + */ + if (type != WC_FUNCDEF) + setunderscore((args && nonempty(args)) ? + ((char *) getdata(lastnode(args))) : ""); /* Warn about "rm *" */ if (type == WC_SIMPLE && interact && unset(RMSTARSILENT) && @@ -4374,7 +4379,7 @@ execfuncdef(Estate state, Eprog redir_prog) Shfunc shf; char *s = NULL; int signum, nprg, sbeg, nstrs, npats, len, plen, i, htok = 0, ret = 0; - int nfunc = 0; + int nfunc = 0, anon_func = 0; Wordcode beg = state->pc, end; Eprog prog; Patprog *pp; @@ -4460,6 +4465,8 @@ execfuncdef(Estate state, Eprog redir_prog) */ LinkList args; + anon_func = 1; + state->pc = end; end += *state->pc++; args = ecgetlist(state, *state->pc++, EC_DUPTOK, &htok); @@ -4515,6 +4522,8 @@ execfuncdef(Estate state, Eprog redir_prog) shfunctab->addnode(shfunctab, ztrdup(s), shf); } } + if (!anon_func) + setunderscore(""); if (!nfunc && redir_prog) { /* For completeness, shouldn't happen */ freeeprog(redir_prog); |